day07
parent
84bc10cbaa
commit
1827398746
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
|
||||
def read_input(filename):
|
||||
sheet = []
|
||||
for line in open(filename).read().splitlines():
|
||||
sheet.append(list(line))
|
||||
return sheet
|
||||
|
||||
# filename = "day07/example_input" # 21
|
||||
filename = "day07/input" # 1560
|
||||
sheet = read_input(filename)
|
||||
|
||||
splits = 0
|
||||
for y in range(0,len(sheet)-1): # skip last line
|
||||
for x in range(0,len(sheet[y])):
|
||||
if sheet[y][x] == "S" or sheet[y][x] == "|":
|
||||
# Shoot ray down
|
||||
if sheet[y+1][x] == "^": # split
|
||||
sheet[y+1][x+1] = "|"
|
||||
sheet[y+1][x-1] = "|"
|
||||
splits += 1
|
||||
else:
|
||||
sheet[y+1][x] = "|"
|
||||
|
||||
|
||||
|
||||
print(f"Total number of splits: {splits}")
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
def read_input(filename):
|
||||
sheet = []
|
||||
for line in open(filename).read().splitlines():
|
||||
sheet.append(list(line))
|
||||
return sheet
|
||||
|
||||
# filename = "day07/example_input" # 40
|
||||
filename = "day07/input" # 1560
|
||||
sheet = read_input(filename)
|
||||
|
||||
for y in range(0,len(sheet)):
|
||||
for x in range(0,len(sheet[y])):
|
||||
if sheet[y][x] == "S":
|
||||
sheet[y][x] = 1
|
||||
if sheet[y][x] == "^":
|
||||
sheet[y][x] = -1
|
||||
if sheet[y][x] == ".":
|
||||
sheet[y][x] = 0
|
||||
|
||||
# "Cheat alert"; figured this out after algorithm hints on reddit
|
||||
for y in range(0,len(sheet)-1): # skip last line
|
||||
for x in range(0,len(sheet[y])):
|
||||
|
||||
# Path starts with weight one
|
||||
# Just add weight to next step
|
||||
# if empty (0), weight stays same
|
||||
# if path is "joined", weights are joined/added
|
||||
|
||||
if sheet[y][x] > 0:
|
||||
# Shoot ray down
|
||||
if sheet[y+1][x] == -1: # split
|
||||
sheet[y+1][x+1] += sheet[y][x]
|
||||
sheet[y+1][x-1] += sheet[y][x]
|
||||
else:
|
||||
sheet[y+1][x] += sheet[y][x]
|
||||
# Last line of sheet contains the added/joined paths, add them up
|
||||
|
||||
paths = 0
|
||||
for i in sheet[-1]:
|
||||
paths += i
|
||||
|
||||
print(f"Total number of paths: {paths}")
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
.......S.......
|
||||
...............
|
||||
.......^.......
|
||||
...............
|
||||
......^.^......
|
||||
...............
|
||||
.....^.^.^.....
|
||||
...............
|
||||
....^.^...^....
|
||||
...............
|
||||
...^.^...^.^...
|
||||
...............
|
||||
..^...^.....^..
|
||||
...............
|
||||
.^.^.^.^.^...^.
|
||||
...............
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
......................................................................S......................................................................
|
||||
.............................................................................................................................................
|
||||
......................................................................^......................................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................................^.^.....................................................................
|
||||
.............................................................................................................................................
|
||||
....................................................................^.^.^....................................................................
|
||||
.............................................................................................................................................
|
||||
...................................................................^.^...^...................................................................
|
||||
.............................................................................................................................................
|
||||
..................................................................^.....^.^..................................................................
|
||||
.............................................................................................................................................
|
||||
.................................................................^.^...^.^.^.................................................................
|
||||
.............................................................................................................................................
|
||||
................................................................^.^...^.^...^................................................................
|
||||
.............................................................................................................................................
|
||||
...............................................................^...^.....^...^...............................................................
|
||||
.............................................................................................................................................
|
||||
..............................................................^...^...^.^.^.^.^..............................................................
|
||||
.............................................................................................................................................
|
||||
.............................................................^.^.....^.^.^.....^.............................................................
|
||||
.............................................................................................................................................
|
||||
............................................................^.^.^.^...^.^.^...^.^............................................................
|
||||
.............................................................................................................................................
|
||||
...........................................................^.......^.^.^.^.^...^.^...........................................................
|
||||
.............................................................................................................................................
|
||||
..........................................................^...^.^.^.^.^...^...^.^.^..........................................................
|
||||
.............................................................................................................................................
|
||||
.........................................................^.^...^.^...^.....^.^.^.^.^.........................................................
|
||||
.............................................................................................................................................
|
||||
........................................................^.^...^.^.^.^.^...^.^.....^.^........................................................
|
||||
.............................................................................................................................................
|
||||
.......................................................^.^.^.^.^.^.^.....^.^.^.....^.^.......................................................
|
||||
.............................................................................................................................................
|
||||
......................................................^.^.^...^.^.^.^.^.^.^.^.^.^.....^......................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................^...............^.^.^.....^...^...^.....................................................
|
||||
.............................................................................................................................................
|
||||
....................................................^.^.^.....^.^...^.^.^.^.....^.^...^.^....................................................
|
||||
.............................................................................................................................................
|
||||
...................................................^.^...^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^...................................................
|
||||
.............................................................................................................................................
|
||||
..................................................^.^.^.^.^.^.^...^.^.^...^.^.^.^.^...^.^.^..................................................
|
||||
.............................................................................................................................................
|
||||
.................................................^.^...^.^.^.^.....^.^.^...^.^.^...^...^.^.^.................................................
|
||||
.............................................................................................................................................
|
||||
................................................^...^...^.^...^.^.^.^.^.^.....^.^...^.^...^.^................................................
|
||||
.............................................................................................................................................
|
||||
...............................................^.....^.....^.^.^...^.^.^.^.^.....^.^.^.......^...............................................
|
||||
.............................................................................................................................................
|
||||
..............................................^.^...^.^.^.^.^...^...^.^.....^...^.^.^.....^.^.^..............................................
|
||||
.............................................................................................................................................
|
||||
.............................................^.^.^.^...^.^.....^.^.^.^.^.^.^.^.^.^.^.^...^...^.^.............................................
|
||||
.............................................................................................................................................
|
||||
............................................^.^.^.^...^.....^.^.^.^...^.^.^.^.^.^...^.^.^...^.^.^............................................
|
||||
.............................................................................................................................................
|
||||
...........................................^.^.^...^...^...^.^.^.^.^.^.....^...^.^.....^.^.....^.^...........................................
|
||||
.............................................................................................................................................
|
||||
..........................................^.....^.......^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.........^..........................................
|
||||
.............................................................................................................................................
|
||||
.........................................^.^...^.....^.^...^.^.^...^.^.^.^.......^.....^.^...^.^.^.^.........................................
|
||||
.............................................................................................................................................
|
||||
........................................^.^...^.^.^.^.^.^.^.......^.^.^...^.^.^...^.^.^.^...^.^...^.^........................................
|
||||
.............................................................................................................................................
|
||||
.......................................^...^...^.^.^.^.......^.^.^.^.^.^.^.^.^...^.^.....^...^.^...^.^.......................................
|
||||
.............................................................................................................................................
|
||||
......................................^.^...^.^.^...^.^.......^.........^...^...^.^...^.^...^.^.^.^...^......................................
|
||||
.............................................................................................................................................
|
||||
.....................................^.^.^.^.^.^.......^.^.^...^.^.^.^.^...^.^...^...^.^...^.^.^.^.^...^.....................................
|
||||
.............................................................................................................................................
|
||||
....................................^.^.^...^.^.^.^.^.^.....^...^.^.^.^.^.^.^.....^.^.^.........^.....^.^....................................
|
||||
.............................................................................................................................................
|
||||
...................................^.^.^.^.....^.^.^.^.^.^.^...^.^.^.....^...^.......^.^.^.^.^.^.^...^.^.^...................................
|
||||
.............................................................................................................................................
|
||||
..................................^...^.^.^.^...^.^...^...^.^...^.^.^...^...^...^.^.....^.....^.^.^...^.^.^..................................
|
||||
.............................................................................................................................................
|
||||
.................................^.^...^.^.^...^.^...^.^.........^.^.^.^.^.^.^.^.^...^...^.^...^.^.^.^.^.^.^.................................
|
||||
.............................................................................................................................................
|
||||
................................^...^.^.^.^.^.^.^.^.^.....^...^.^.........^...^.^...^...^.....^.^.....^...^.^................................
|
||||
.............................................................................................................................................
|
||||
...............................^.^.^.^...^.^.........^.^.^.^.^.....^.^.....^.^...^.^.^.^.^...^.^.^.....^.^.^.^...............................
|
||||
.............................................................................................................................................
|
||||
..............................^.^.^.^...^.^.^.^.^.^.....^.^.^...^...^.^.^.^.^...^.......^.^.^.^.^...^.^.....^.^..............................
|
||||
.............................................................................................................................................
|
||||
.............................^.^...^...^.........^...^.....^.^.^.^.^.^.^.^...^...^...^.^.^.^.^.....^.^.....^...^.............................
|
||||
.............................................................................................................................................
|
||||
............................^.^.^.^...^...^.^...^.^.......^...^.^.^...^.^.^.^.^...^...^.^.......^.^.^...^.^.^.^.^............................
|
||||
.............................................................................................................................................
|
||||
...........................^.^.^.^...^.^.^.^.^.^.^.^...^.^...^.^...^.^.^...^...^.^.^.^.^.^.....^...^.^.^.^.^.^...^...........................
|
||||
.............................................................................................................................................
|
||||
..........................^.....^.^.^.....^.^.......^.^...^...^.^.^...^.....^.^.^...^...^.^...^.^.^.^.^.^...^.^...^..........................
|
||||
.............................................................................................................................................
|
||||
.........................^.^.....^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^...^.^.....^.^...^.....^.^...^.^.........................
|
||||
.............................................................................................................................................
|
||||
........................^...^...^.^.^...^...........^.^...^.^.....^.^...^...^...^.....^.^.....^.^.^.........^.^...^.^........................
|
||||
.............................................................................................................................................
|
||||
.......................^.^.^.^...^.......^.^...^.^...^.^.^.....^.^.^.^.^.......^.^.^.^...^.^.....^.^.^.^...^.^.^.^...^.......................
|
||||
.............................................................................................................................................
|
||||
......................^.^.^.........^.^...^.^.^.....^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.^...^.^.^.^.^.^.^.^...^......................
|
||||
.............................................................................................................................................
|
||||
.....................^...^...^.^.^.^.....^...^.^...^.^.^...^.^.^...^.......^.^.^.^.^.^.^.^.^...^.^.....^...^.^.....^.^.^.....................
|
||||
.............................................................................................................................................
|
||||
....................^.^.^.^...^.^.^.^.^.^...^.^.^...^.....^...^...^.^...^.^.^.^...^.^.^.^.....^.^.^.^.....^...^.^.^.^...^....................
|
||||
.............................................................................................................................................
|
||||
...................^.......^.....^.^.^.^.^.^...^.^...^.^.^.....^...^...^.^.^.......^.^.^...^...^...^.^.^.....^.^.^...^.^.^...................
|
||||
.............................................................................................................................................
|
||||
..................^.^.^.^...^.^.^.^...^.^...^.^.^...^.^.^...^.^.....^.^.^.^.^.^...^...^.^.^.^.^.^.^.^.^...^.....^.^.....^.^..................
|
||||
.............................................................................................................................................
|
||||
.................^.^.^.^.^.^.^.^...^.^.^...^...^.^...^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.....^.....^.....^.^...^.^.^.^.^.....^.^.................
|
||||
.............................................................................................................................................
|
||||
................^.^...^.^.....^.^...^.^.^.....^...^...^.........^.^.^.^.^...^.^.^.^.....^.^.....^.^.....^.^.^.^.^.....^.^...^................
|
||||
.............................................................................................................................................
|
||||
...............^.^.....^.^...^.^...^.^.....^.^.^.^.^...^.^...^...^...^.^.^.^.^.^...^...^.^...^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...............
|
||||
.............................................................................................................................................
|
||||
..............^.^.....^.^.^...^.^.^.^...^.^.^.....^.^.^.^.^.^.^.^.^.^...^...^.^...^.^.......^...^.......^...^.^.....^.^.^...^.^..............
|
||||
.............................................................................................................................................
|
||||
.............^.^.^.^...^.....^.^.^.^.^...^...........^...^.^.^.^.....^.^.^.^.^...^...^.^.....^.^.^.^.^...^.^...^.^...^...^.....^.............
|
||||
.............................................................................................................................................
|
||||
............^.....^.^.^.^.^.^...^...^.^.^...^.^...^.^.^.^.^.^.^.^.....^.^.^.^.^.^...^.^.^.^...^.^...^.....^.....^.^.....^.^.^.^.^............
|
||||
.............................................................................................................................................
|
||||
...........^.^...^.^...^.^...^.^.^.....^.^.^.^...^.....^.^...^.....^.^.^...^.^.^...^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^...^...........
|
||||
.............................................................................................................................................
|
||||
..........^.^.......^.^.^.....^...^.^...^.^.^.^...^.^.^.^...^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^...^.^.^.^.^.....^.^.^...^.^..........
|
||||
.............................................................................................................................................
|
||||
.........^.^.....^...^.^.^.^.^.^...^.....^.^.^.^.^.....^.^.^.^.^...^.......^...^.^.^.....^.^.^.^.^.^.^.^.^.^.....^.^...........^...^.........
|
||||
.............................................................................................................................................
|
||||
........^...^.......^.^.^.....^.^.^.^.^.^.^...^.....^...^.^.^.^.......^.^.^.........^...^...^.^...^.^.....^...^...^...^...^.....^...^........
|
||||
.............................................................................................................................................
|
||||
.......^...^.^.^...^...^.^.^.^...^...^.^.^...^.^.^.....^...^.^.^.^.......^.^...^.^.^.^.^...^...^.^.^...^.^.^...^.^.^.^.^.^...^...^...^.......
|
||||
.............................................................................................................................................
|
||||
......^.......^.......^.^.^.^.^.^...^.^...^.....^...^.^.^.^.^.^...^.^...^.^.^...^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.....^.^.^.^.^.^......
|
||||
.............................................................................................................................................
|
||||
.....^.^.....^.^.^.^...^.........^.^.^.^.^.^.^...^.^...^.^.^...^.....^...^.......^.^.^.^.^.......^.^.....^.^.^.^...^.^.^.^...^.^.......^.....
|
||||
.............................................................................................................................................
|
||||
....^.^.^.^...^.^.^.^.^.^...^...^.^.^.....^.....^...^.^.^.^.^.^.....^.^.....^.^.^...^.^.^.^.^.^.^.^.........^.^.......^.^...^.^.^.....^.^....
|
||||
.............................................................................................................................................
|
||||
...^.^.^.^.^.^.^...^...^.....^.^.^...^.^.^.^.^.^.^.^.....^.^...^...^.^.^.^.^...^.^...^.....^.^.^.^.^.^.^.^.^.^...^.^.......^.^...^.^...^.^...
|
||||
.............................................................................................................................................
|
||||
..^.^.^.^.^.^.^.^.......^...^.....^.^...^.^.^.^.^.^.^.^...^.....^.^.^.^...^.^.^.^...^...^.^.^.^.^.^.^.^.......^.^.^.....^.^...^.^.^...^...^..
|
||||
.............................................................................................................................................
|
||||
.^.^...^...^.^.^.^.....^.^.^.^.^...^.^...^.^.^...^.^.^.^.^.....^.^.......^.....^.....^...^...^.^.^.^.^...^.^...^.^...^.^.^.^.^.^.^...^.^...^.
|
||||
.............................................................................................................................................
|
||||
Loading…
Reference in New Issue