From 47d321a993977a699a8143c6a64bd196066bdb34 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Sun, 24 Nov 2024 19:21:15 +0100 Subject: [PATCH] Started 2017/13 --- 2017/13/13.md | 196 ++++++++++++++++++++++++++++++++++++++++++++ 2017/13/solution.py | 29 +++++++ solution.py | 2 + 3 files changed, 227 insertions(+) create mode 100644 2017/13/13.md create mode 100644 2017/13/solution.py diff --git a/2017/13/13.md b/2017/13/13.md new file mode 100644 index 0000000..25ce9f1 --- /dev/null +++ b/2017/13/13.md @@ -0,0 +1,196 @@ +## \-\-- Day 13: Packet Scanners \-\-- + +You need to cross a vast *firewall*. The firewall consists of several +layers, each with a *security scanner* that moves back and forth across +the layer. To succeed, you must not be detected by a scanner. + +By studying the firewall briefly, you are able to record (in your puzzle +input) the *depth* of each layer and the *range* of the scanning area +for the scanner within it, written as `depth: range`. Each layer has a +thickness of exactly `1`. A layer at depth `0` begins immediately inside +the firewall; a layer at depth `1` would start immediately after that. + +For example, suppose you\'ve recorded the following: + + 0: 3 + 1: 2 + 4: 4 + 6: 4 + +This means that there is a layer immediately inside the firewall (with +range `3`), a second layer immediately after that (with range `2`), a +third layer which begins at depth `4` (with range `4`), and a fourth +layer which begins at depth 6 (also with range `4`). Visually, it might +look like this: + + 0 1 2 3 4 5 6 + [ ] [ ] ... ... [ ] ... [ ] + [ ] [ ] [ ] [ ] + [ ] [ ] [ ] + [ ] [ ] + +Within each layer, a security scanner moves back and forth within its +range. Each security scanner starts at the top and moves down until it +reaches the bottom, then moves up until it reaches the top, and repeats. +A security scanner takes *one picosecond* to move one step. Drawing +scanners as `S`, the first few picoseconds look like this: + + Picosecond 0: + 0 1 2 3 4 5 6 + [S] [S] ... ... [S] ... [S] + [ ] [ ] [ ] [ ] + [ ] [ ] [ ] + [ ] [ ] + + Picosecond 1: + 0 1 2 3 4 5 6 + [ ] [ ] ... ... [ ] ... [ ] + [S] [S] [S] [S] + [ ] [ ] [ ] + [ ] [ ] + + Picosecond 2: + 0 1 2 3 4 5 6 + [ ] [S] ... ... [ ] ... [ ] + [ ] [ ] [ ] [ ] + [S] [S] [S] + [ ] [ ] + + Picosecond 3: + 0 1 2 3 4 5 6 + [ ] [ ] ... ... [ ] ... [ ] + [S] [S] [ ] [ ] + [ ] [ ] [ ] + [S] [S] + +Your plan is to hitch a ride on a packet about to move through the +firewall. The packet will travel along the top of each layer, and it +moves at *one layer per picosecond*. Each picosecond, the packet moves +one layer forward (its first move takes it into layer 0), and then the +scanners move one step. If there is a scanner at the top of the layer +*as your packet enters it*, you are *caught*. (If a scanner moves into +the top of its layer while you are there, you are *not* caught: it +doesn\'t have time to notice you before you leave.) If you were to do +this in the configuration above, marking your current position with +parentheses, your passage through the firewall would look like this: + + Initial state: + 0 1 2 3 4 5 6 + [S] [S] ... ... [S] ... [S] + [ ] [ ] [ ] [ ] + [ ] [ ] [ ] + [ ] [ ] + + Picosecond 0: + 0 1 2 3 4 5 6 + (S) [S] ... ... [S] ... [S] + [ ] [ ] [ ] [ ] + [ ] [ ] [ ] + [ ] [ ] + + 0 1 2 3 4 5 6 + ( ) [ ] ... ... [ ] ... [ ] + [S] [S] [S] [S] + [ ] [ ] [ ] + [ ] [ ] + + + Picosecond 1: + 0 1 2 3 4 5 6 + [ ] ( ) ... ... [ ] ... [ ] + [S] [S] [S] [S] + [ ] [ ] [ ] + [ ] [ ] + + 0 1 2 3 4 5 6 + [ ] (S) ... ... [ ] ... [ ] + [ ] [ ] [ ] [ ] + [S] [S] [S] + [ ] [ ] + + + Picosecond 2: + 0 1 2 3 4 5 6 + [ ] [S] (.) ... [ ] ... [ ] + [ ] [ ] [ ] [ ] + [S] [S] [S] + [ ] [ ] + + 0 1 2 3 4 5 6 + [ ] [ ] (.) ... [ ] ... [ ] + [S] [S] [ ] [ ] + [ ] [ ] [ ] + [S] [S] + + + Picosecond 3: + 0 1 2 3 4 5 6 + [ ] [ ] ... (.) [ ] ... [ ] + [S] [S] [ ] [ ] + [ ] [ ] [ ] + [S] [S] + + 0 1 2 3 4 5 6 + [S] [S] ... (.) [ ] ... [ ] + [ ] [ ] [ ] [ ] + [ ] [S] [S] + [ ] [ ] + + + Picosecond 4: + 0 1 2 3 4 5 6 + [S] [S] ... ... ( ) ... [ ] + [ ] [ ] [ ] [ ] + [ ] [S] [S] + [ ] [ ] + + 0 1 2 3 4 5 6 + [ ] [ ] ... ... ( ) ... [ ] + [S] [S] [S] [S] + [ ] [ ] [ ] + [ ] [ ] + + + Picosecond 5: + 0 1 2 3 4 5 6 + [ ] [ ] ... ... [ ] (.) [ ] + [S] [S] [S] [S] + [ ] [ ] [ ] + [ ] [ ] + + 0 1 2 3 4 5 6 + [ ] [S] ... ... [S] (.) [S] + [ ] [ ] [ ] [ ] + [S] [ ] [ ] + [ ] [ ] + + + Picosecond 6: + 0 1 2 3 4 5 6 + [ ] [S] ... ... [S] ... (S) + [ ] [ ] [ ] [ ] + [S] [ ] [ ] + [ ] [ ] + + 0 1 2 3 4 5 6 + [ ] [ ] ... ... [ ] ... ( ) + [S] [S] [S] [S] + [ ] [ ] [ ] + [ ] [ ] + +In this situation, you are *caught* in layers `0` and `6`, because your +packet entered the layer when its scanner was at the top when you +entered it. You are *not* caught in layer `1`, since the scanner moved +into the top of the layer once you were already there. + +The *severity* of getting caught on a layer is equal to its *depth* +multiplied by its *range*. (Ignore layers in which you do not get +caught.) The severity of the whole trip is the sum of these values. In +the example above, the trip severity is `0*3 + 6*4 = 24`. + +Given the details of the firewall you\'ve recorded, if you leave +immediately, *what is the severity of your whole trip*? + +To begin, [get your puzzle input](13/input). + +Answer: diff --git a/2017/13/solution.py b/2017/13/solution.py new file mode 100644 index 0000000..4b5e09c --- /dev/null +++ b/2017/13/solution.py @@ -0,0 +1,29 @@ +#!/bin/python3 +import sys,re +from pprint import pprint +sys.path.insert(0, '../../') +from fred import list2int + +input_f = 'test' + +part = 1 +######################################### +# # +# Part 1 # +# # +######################################### + +if part == 1: + with open(input_f) as file: + for line in file: + + + + +######################################### +# # +# Part 2 # +# # +######################################### +if part == 2: + exit() diff --git a/solution.py b/solution.py index beabd72..4b5e09c 100644 --- a/solution.py +++ b/solution.py @@ -1,6 +1,8 @@ #!/bin/python3 import sys,re from pprint import pprint +sys.path.insert(0, '../../') +from fred import list2int input_f = 'test'