Added 2017/13 part 2

This commit is contained in:
FrederikBaerentsen 2024-11-25 14:57:38 +01:00
parent 31fec7fe38
commit e4caab3731
2 changed files with 66 additions and 12 deletions

View File

@ -193,8 +193,6 @@ immediately, *what is the severity of your whole trip*?
Your puzzle answer was `1844`. Your puzzle answer was `1844`.
The first half of this puzzle is complete! It provides one gold star: \*
## \-\-- Part Two \-\-- {#part2} ## \-\-- Part Two \-\-- {#part2}
Now, you need to pass through the firewall without being caught - easier 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 *What is the fewest number of picoseconds* that you need to delay the
packet to pass through the firewall without being caught? 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). input](13/input).

View File

@ -6,7 +6,7 @@ from fred import list2int, ppprint
input_f = 'input' input_f = 'input'
part = 2 part = 3
######################################### #########################################
# # # #
@ -16,8 +16,6 @@ part = 2
grid = [] grid = []
if part == 1: if part == 1:
for i in range(0,100): for i in range(0,100):
grid.append([]) grid.append([])
@ -103,7 +101,7 @@ if part == 1:
# # # #
######################################### #########################################
if part == 2: if part == 2:
grid_length = 100 grid_length = 7
for i in range(0,grid_length): for i in range(0,grid_length):
grid.append([]) grid.append([])
with open(input_f) as file: with open(input_f) as file:
@ -115,6 +113,8 @@ if part == 2:
count = 0 count = 0
hit = [] hit = []
debug = 0
direction = 1 direction = 1
packet_loc = 0 packet_loc = 0
@ -144,10 +144,11 @@ if part == 2:
#print(packet_loc,scanner_loc) #print(packet_loc,scanner_loc)
for idx,i in enumerate(grid): for idx,i in enumerate(grid):
debug += 1
if scanner_loc[idx] == 0 and packet_loc == idx: if scanner_loc[idx] == 0 and packet_loc == idx:
hit.append(idx) hit.append(idx)
#print('Got hit at',idx) print('Got hit at',idx)
got_hit = True got_hit = True
elif len(grid[idx]) != 0: elif len(grid[idx]) != 0:
loc = scanner_loc[idx] % len(grid[idx]) loc = scanner_loc[idx] % len(grid[idx])
@ -158,9 +159,12 @@ if part == 2:
directions[idx] = 1 directions[idx] = 1
if got_hit: if got_hit:
break break
#print(grid)
packet_loc += 1 packet_loc += 1
if len(hit) == 0: if len(hit) == 0:
print(abs(start_loc)) print(abs(start_loc))
print('Debug:',debug)
break break
#input() #input()
#print(hit) #print(hit)
@ -171,3 +175,49 @@ if part == 2:
#print(damage) #print(damage)
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)