this time with no legal info
This commit is contained in:
33
7/ex1.py
Normal file
33
7/ex1.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import numpy as np
|
||||
|
||||
count = 0
|
||||
|
||||
grid = []
|
||||
|
||||
with open('input.txt') as file:
|
||||
num_cols = len(file.readline().strip('\n'))
|
||||
file.seek(0)
|
||||
num_lines = 0
|
||||
for line in file:
|
||||
num_lines += 1
|
||||
for i in range(num_cols):
|
||||
grid.append(line[i])
|
||||
|
||||
grid = np.array(grid).reshape((num_lines, num_cols))
|
||||
|
||||
beams = set()
|
||||
|
||||
for row in grid:
|
||||
for i in range(len(row)):
|
||||
if row[i] == 'S':
|
||||
beams.add(i)
|
||||
elif row[i] == '^':
|
||||
if i in beams:
|
||||
count += 1
|
||||
beams.remove(i)
|
||||
if i - 1 not in beams:
|
||||
beams.add(i - 1)
|
||||
if i + 1 not in beams:
|
||||
beams.add(i + 1)
|
||||
|
||||
print(count)
|
||||
32
7/ex2.py
Normal file
32
7/ex2.py
Normal file
@@ -0,0 +1,32 @@
|
||||
def count_timelines(grid): # Dynamic programming my beloved/behated
|
||||
num_rows = len(grid)
|
||||
num_cols = len(grid[0])
|
||||
|
||||
counts = [1 if grid[0][c] == 'S' else 0 for c in range(num_cols)]
|
||||
|
||||
for r in range(num_rows):
|
||||
next_counts = [0] * num_cols
|
||||
row = grid[r]
|
||||
for c in range(num_cols):
|
||||
k = counts[c]
|
||||
if k == 0:
|
||||
continue
|
||||
if row[c] == '^':
|
||||
if c > 0:
|
||||
next_counts[c - 1] += k
|
||||
if c + 1 < num_cols:
|
||||
next_counts[c + 1] += k
|
||||
else:
|
||||
next_counts[c] += k
|
||||
counts = next_counts
|
||||
|
||||
return sum(counts)
|
||||
|
||||
|
||||
with open('input.txt', 'r') as f:
|
||||
lines = [line.rstrip('\n') for line in f]
|
||||
|
||||
grid = [list(line) for line in lines]
|
||||
|
||||
total = count_timelines(grid)
|
||||
print(total)
|
||||
142
7/input.txt
Normal file
142
7/input.txt
Normal file
@@ -0,0 +1,142 @@
|
||||
......................................................................S......................................................................
|
||||
.............................................................................................................................................
|
||||
......................................................................^......................................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................................^.^.....................................................................
|
||||
.............................................................................................................................................
|
||||
....................................................................^...^....................................................................
|
||||
.............................................................................................................................................
|
||||
...................................................................^.....^...................................................................
|
||||
.............................................................................................................................................
|
||||
..................................................................^...^...^..................................................................
|
||||
.............................................................................................................................................
|
||||
.................................................................^.^...^.^.^.................................................................
|
||||
.............................................................................................................................................
|
||||
................................................................^.^.......^.^................................................................
|
||||
.............................................................................................................................................
|
||||
...............................................................^...^...^.^.^.^...............................................................
|
||||
.............................................................................................................................................
|
||||
..............................................................^.^.^...^.......^..............................................................
|
||||
.............................................................................................................................................
|
||||
.............................................................^...^.^.^.^...^.^.^.............................................................
|
||||
.............................................................................................................................................
|
||||
............................................................^.^.^.^...^.......^.^............................................................
|
||||
.............................................................................................................................................
|
||||
...........................................................^.^.^.^.^.^.^.^.^...^.^...........................................................
|
||||
.............................................................................................................................................
|
||||
..........................................................^.....^.^.^.^.^.....^...^..........................................................
|
||||
.............................................................................................................................................
|
||||
.........................................................^.^.....^.^.^.^.^...^.^.^.^.........................................................
|
||||
.............................................................................................................................................
|
||||
........................................................^.^.^.^.^.^.^.^...^...^.....^........................................................
|
||||
.............................................................................................................................................
|
||||
.......................................................^.^.^.^.^.^.^.......^...^.....^.......................................................
|
||||
.............................................................................................................................................
|
||||
......................................................^.^.^.^...^.^.....^.^.^.^.^...^.^......................................................
|
||||
.............................................................................................................................................
|
||||
.....................................................^.^.^.^.^.^.^.....^.....^...^.^.^.^.....................................................
|
||||
.............................................................................................................................................
|
||||
....................................................^.^...^.^.......^.^.^.......^...^.^.^....................................................
|
||||
.............................................................................................................................................
|
||||
...................................................^...^.^...^...^.^.^.^.^...^...^.^.....^...................................................
|
||||
.............................................................................................................................................
|
||||
..................................................^.....^...^.^.^.....^...^.^...^.......^.^..................................................
|
||||
.............................................................................................................................................
|
||||
.................................................^.^.^.^.^.^.^.^...^.^.^.^.^.....^.^...^.^.^.................................................
|
||||
.............................................................................................................................................
|
||||
................................................^.^...^.^.....^.^.....^...^.^.^.....^.^...^.^................................................
|
||||
.............................................................................................................................................
|
||||
...............................................^.........^.^.^.^.^.^.^.^...^.^.^.^...........^...............................................
|
||||
.............................................................................................................................................
|
||||
..............................................^.^.......^...^...^...^...^.^.^.^.^.^.^.^.^.^.^.^..............................................
|
||||
.............................................................................................................................................
|
||||
.............................................^.........^.^.^.^.^.^.^...^.^.^.^.^...^.^.^.^.^.^.^.............................................
|
||||
.............................................................................................................................................
|
||||
............................................^.^...^...^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^............................................
|
||||
.............................................................................................................................................
|
||||
...........................................^.^.^.^...^.^.^.^.^.^.....^.^.^.^.^.^.^...^.^.^.^.^...^...........................................
|
||||
.............................................................................................................................................
|
||||
..........................................^.....^.^.......^.^.^.^.^.^.^.....^.^.^.^.....^.^.^.^.^.^..........................................
|
||||
.............................................................................................................................................
|
||||
.........................................^.....^.^.^.^.^.^.^...^.^.^.....^.....^.^.....^.^.......^.^.........................................
|
||||
.............................................................................................................................................
|
||||
........................................^.^...^.^.^.^...^...^.^.^.^.^...^.^.^.^...^.....^.^.^...^...^........................................
|
||||
.............................................................................................................................................
|
||||
.......................................^.^.^.^.^.......^...^.^.^.^...^...^.^.^...^...^.^.^...........^.......................................
|
||||
.............................................................................................................................................
|
||||
......................................^.^...^.^.^.^...^...^.^.^.........^.^.^.^...^.^.^.^...^...^.....^......................................
|
||||
.............................................................................................................................................
|
||||
.....................................^.........^.^.^.^.^.^...^.........^.^.^.^.^.^.^.^.^...^.^.^...^...^.....................................
|
||||
.............................................................................................................................................
|
||||
....................................^.^.^...^.^.^.....^.^.^.^.^.....^.^.^...^...^...^.^.^.^...^...^...^.^....................................
|
||||
.............................................................................................................................................
|
||||
...................................^...^.^.^.^.^...^...^...^...^.^.^.^.^...^.^.^...^...^.^.^.........^.^.^...................................
|
||||
.............................................................................................................................................
|
||||
..................................^.^.^.^...^.^.....^.^.^.^.^...^...^.^.^.^.....^...^...^.^...^.^...^.^...^..................................
|
||||
.............................................................................................................................................
|
||||
.................................^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.......^...^.^.^.......^...^.^.^.^.^.^.^.^.................................
|
||||
.............................................................................................................................................
|
||||
................................^.^.^...^.^...^.^...^.^.^.^...^.^...^.^.^.^.....^.....^.^.^.^.^.......^...^.^................................
|
||||
.............................................................................................................................................
|
||||
...............................^.^.^...^.^.^...^.^.^.^.^.^.....^.^.^.^...^.^.^.^.^.^.^.....^.^.^.^.....^.....^...............................
|
||||
.............................................................................................................................................
|
||||
..............................^.^...^.^.^.^.^.^...^.^.^.^...^.^.^...^.^...^.^...^.^.^.^...^.^.....^.^.^.....^.^..............................
|
||||
.............................................................................................................................................
|
||||
.............................^.^.^.^.^...^.^.^.^.^...^...^.^.^.^.^.........^.^.^...^.^...^.^...^.^.^...^...^.^.^.............................
|
||||
.............................................................................................................................................
|
||||
............................^...^.^...^.^...^.^.^.^...^.^.^.^.^...^.^.......^.^.^.^...^.^...^.^.^...^.^.........^............................
|
||||
.............................................................................................................................................
|
||||
...........................^.^.^...^.^.^.^...^.^.^.....^.^.^.^.......^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^...^.^...........................
|
||||
.............................................................................................................................................
|
||||
..........................^.^...^...^.^.^...^.^.^.^.^.^.^.^...^.^.^.^...^.^.^.^.^.^...^...^.^.^.^...^.^.^.^.^...^.^..........................
|
||||
.............................................................................................................................................
|
||||
.........................^.^.^...^.^.^...^.^.^.^.....^.^...^...^.^...^.^.....^...^.^.^.^.^.^.^.....^.^.^.......^...^.........................
|
||||
.............................................................................................................................................
|
||||
........................^...^.^.^.^.^.^...^.^...^.^...^.^.........^.^.....^.^.^...........^...^.^.^.^...^.^.^.^.^.^.^........................
|
||||
.............................................................................................................................................
|
||||
.......................^.^.^.....^.^.^.....^.^.^.^.^.^...^.^.^...^.^.^.^.^...^.....^.^...^.^.^...^.^.^.^...^.^.^.^.^.^.......................
|
||||
.............................................................................................................................................
|
||||
......................^.^.^.^.^.^...^...^.^.......^...^.^...^.^...^.^.^.^.^.^.^...^.....^...^...^...^.^...^.^...^.^.^.^......................
|
||||
.............................................................................................................................................
|
||||
.....................^.^...^.^.^.^.^...^.^.^...^.^.^.^...^...^.^.^...^.....^.^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^.....................
|
||||
.............................................................................................................................................
|
||||
....................^...^.^.^.^.^.....^.^.^.......^.^.^.^.^.^.^.^.......^...^...^.^.....^.....^...^.^...^.^.^.^.^.^.^...^....................
|
||||
.............................................................................................................................................
|
||||
...................^.^...^.^.^.^.^.^.^.^.............^.........^.^.^...^...^...^.^.........^.^.....^.^...^.....^.^.^.^...^...................
|
||||
.............................................................................................................................................
|
||||
..................^.^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.^.^.....^...^.^.^.^.........^.^...^...^.^.......^.....^.^.^.....^.^...^..................
|
||||
.............................................................................................................................................
|
||||
.................^.^.^...^...^.^.^.^.^.^.^.^.^.^...^...^.^...^.^.^.^...^.^.^.^.^.^.^...^.^.......^.^...^.^.........^...^.^.^.................
|
||||
.............................................................................................................................................
|
||||
................^.^.^.....^...^.^...^.^.^.^.^.^...^.^...^.^.^.^.^.^.....^.^.^.^.^.....^...^.....^.^.^.....^.^.^.^.^...^.^...^................
|
||||
.............................................................................................................................................
|
||||
...............^.^.....^.^...^...^...^.^.^.......^...^.^...^.^.^...^.^.^.......^.^...^.^.^...^...^.^.....^...^...^.^.....^...^...............
|
||||
.............................................................................................................................................
|
||||
..............^.^.^.....^.^.^.^.^...^...^.^...^...^.^.^.....^...^.^.^.^.^...^.^.^.^.......^.^.....^...^.^...^.^.^...^.^.^...^.^..............
|
||||
.............................................................................................................................................
|
||||
.............^.^.^.^.^.....^.^...^.^...^...^.^.^...^.^.^...^...^.^.^.^.^...^.^.^.^.^.^.^.^...^.^.^.^.^...^...^.^.^.^...^.....^.^.............
|
||||
.............................................................................................................................................
|
||||
............^.^.^...^.......^.^...^.^.^.......^.^...^.^.^...^.^.^...........^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.......^.^.^.^.^.^.^.^............
|
||||
.............................................................................................................................................
|
||||
...........^.....^.^...^...^.^...^...^...^.^.^...^...^...^.^.^...^.....^...^...^...^.....^...^.....^.^.^...^.^.^...^.^...^.^.^.^.^...........
|
||||
.............................................................................................................................................
|
||||
..........^.^.^.^.^.......^.^.^.^.^.^.....^.....^.^...^.^.^...^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^...^.^.....^...^.^.^..........
|
||||
.............................................................................................................................................
|
||||
.........^...^.^.^...^.^.^.^.^.....^...^...^.^.^...^.^.^...^...^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.....^.^.^.......^.^.^.^.........
|
||||
.............................................................................................................................................
|
||||
........^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^.......^.^.^.^.^.^.^...^.^.^.....^...^.^.....^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^........
|
||||
.............................................................................................................................................
|
||||
.......^.^.......^.^.^.^.^.^.^...^.^.^.^.......^.....^...^.^.^.^.^.^.^.^...^.^...^...^.^.....^.^.....^...^.^.......^...^.^.^.^.^.^...^.......
|
||||
.............................................................................................................................................
|
||||
......^.^...^...^.^.^...^...^.^.^.^.^.^...^.^...^.....^.^.^.^.......^...^...^.^.....^.^.^.....^.^...^.^.....^.^.^.^.^.....^.....^.....^......
|
||||
.............................................................................................................................................
|
||||
.....^.^.^.^.....^.^.^.^.^.^.^...^.^.....^.^.^.....^.^.........^.^...^.^.....^...^.^.^.^.^.......^.^.....^.....^.^.^.^.^.^.^.....^.^...^.....
|
||||
.............................................................................................................................................
|
||||
....^...^.....^.^...^...^.^.^.........^.^.^.^.^.^.^.^.^.^.^.^...^.^.....^.....^.^.^.....^.^.^.^.^.^.....^.^.^.^.^...^.^.^.^...^.^.^.^...^....
|
||||
.............................................................................................................................................
|
||||
...^.....^.^.^.^...^.^.^.^.^.^.^...^.^.......^.^...^...^.^...^.^.^.......^.^.^.^.^.^.^.^.^...^.^.^.^...^.^.....^.^.^.^.^...^.^.^...^.^.^.^...
|
||||
.............................................................................................................................................
|
||||
..^.^.^.^...^.^.^.^.^...^.^.^.^.....^.^...^...^.^.^.^.....^.^.^.....^.^...^.^.^...^.^.^.........^.........................^.^.^.^.^.^...^.^..
|
||||
.............................................................................................................................................
|
||||
.^.^.....^.^.^.^.^.^.^...^.^.^...^.^...^.^.^.^...^.....^.^...^.^...^.^.^.^.....^...^.^...^...^.^.^.....^.^...^.^...^...^.^.^.^.^.^.^...^.^.^.
|
||||
.............................................................................................................................................
|
||||
Reference in New Issue
Block a user