-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday3.py
More file actions
39 lines (33 loc) · 810 Bytes
/
day3.py
File metadata and controls
39 lines (33 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
import pandas as pd
with open('/Users/relyea/data/input_day3.txt') as aoc_fp:
input_data = [theline.rstrip() for theline in aoc_fp.readlines()]
# 8 minutes
# input_data = [
# '..##.......',
# '#...#...#..',
# '.#....#..#.',
# '..#.#...#.#',
# '.#...##..#.',
# '..#.##.....',
# '.#.#.#....#',
# '.#........#',
# '#.##...#...',
# '#...##....#',
# '.#..#...#.#'
# ]
def count_trees(themap, dx, dy):
ix = dx
iy = dy
ntrees = 0
while iy < len(themap):
ntrees += int(themap[iy][ix % len(themap[0])] == '#')
ix += dx
iy += dy
return ntrees
themult = 1
for (dx,dy) in [(1,1),(3,1),(5,1),(7,1),(1,2)]:
ntrees = count_trees(input_data, dx, dy)
print(ntrees)
themult *= ntrees
print(themult)