diff --git a/2017/13/13.md b/2017/13/13.md index e5f2de5..5ea7199 100644 --- a/2017/13/13.md +++ b/2017/13/13.md @@ -193,8 +193,6 @@ immediately, *what is the severity of your whole trip*? Your puzzle answer was `1844`. -The first half of this puzzle is complete! It provides one gold star: \* - ## \-\-- Part Two \-\-- {#part2} Now, you need to pass through the firewall without being caught - easier @@ -320,7 +318,13 @@ picoseconds you would need to delay to get through safely is `10`. *What is the fewest number of picoseconds* that you need to delay the packet to pass through the firewall without being caught? -Answer: +Your puzzle answer was `3897604`. -Although it hasn\'t changed, you can still [get your puzzle +Both parts of this puzzle are complete! They provide two gold stars: +\*\* + +At this point, you should [return to your Advent calendar](/2017) and +try another puzzle. + +If you still want to see it, you can [get your puzzle input](13/input). diff --git a/2017/13/solution.py b/2017/13/solution.py index ad41287..9363235 100644 --- a/2017/13/solution.py +++ b/2017/13/solution.py @@ -6,7 +6,7 @@ from fred import list2int, ppprint input_f = 'input' -part = 2 +part = 3 ######################################### # # @@ -16,8 +16,6 @@ part = 2 grid = [] - - if part == 1: for i in range(0,100): grid.append([]) @@ -103,7 +101,7 @@ if part == 1: # # ######################################### if part == 2: - grid_length = 100 + grid_length = 7 for i in range(0,grid_length): grid.append([]) with open(input_f) as file: @@ -115,6 +113,8 @@ if part == 2: count = 0 hit = [] + debug = 0 + direction = 1 packet_loc = 0 @@ -144,11 +144,12 @@ if part == 2: #print(packet_loc,scanner_loc) for idx,i in enumerate(grid): + debug += 1 if scanner_loc[idx] == 0 and packet_loc == idx: - hit.append(idx) - #print('Got hit at',idx) - got_hit = True + hit.append(idx) + print('Got hit at',idx) + got_hit = True elif len(grid[idx]) != 0: loc = scanner_loc[idx] % len(grid[idx]) scanner_loc[idx] += directions[idx] @@ -158,9 +159,12 @@ if part == 2: directions[idx] = 1 if got_hit: break + #print(grid) packet_loc += 1 + if len(hit) == 0: print(abs(start_loc)) + print('Debug:',debug) break #input() #print(hit) @@ -170,4 +174,50 @@ if part == 2: # damage += (i*len(grid[i])) #print(damage) - \ No newline at end of file + + +if part == 3: + grid_length = 100 + scanners = {} + for i in range(0,grid_length): + grid.append([]) + with open(input_f) as file: + for line in file: + l = line.rstrip().split(': ') + l = list2int(l) + for i in range(0,l[1]): + grid[l[0]].append('[ ]') + + for idx,i in enumerate(grid): + scanners[idx] = len(i) + + debug = 0 + damage = 0 + delay = 0 + End = False + + + while not End: + damage = False + for spot, range in enumerate(grid): + debug += 1 + #print(spot%(2*(scanners[spot]-1))) + + if not (delay+spot)%(2*(len(range)-1)) and len(range) > 0: + #print('hit at ', spot) + damage += 1 + break + if damage: + delay += 1 + else: + End = True + + #print('-----') + #print() + #print('debug',debug) + #input() + print(debug) + print(delay) + #pprint(grid) + #print(scanners) +