-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3.py
89 lines (71 loc) · 1.37 KB
/
day3.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 3 14:19:21 2020
@author: rundx
"""
import numpy as np
f = open('day3.txt', 'r')
path = np.zeros((323,31))
row = 0
for line in f:
temp = line.rstrip()
col = 0
for char in temp:
if char == '.':
char = 0
elif char == '#':
char = 1
path[row][col] = char
col+=1
row+=1
pos = [0,0]
treesHit = 0
while pos[0] < 322:
pos[0]+=1
pos[1]+=3
pos[1] = pos[1] % 31
print(pos)
if path[pos[0]][pos[1]] == 1:
treesHit += 1
prdTrees = treesHit
pos = [0,0]
treesHit = 0
while pos[0] < 322:
pos[0]+=1
pos[1]+=1
pos[1] = pos[1] % 31
print(pos)
if path[pos[0]][pos[1]] == 1:
treesHit += 1
prdTrees *= treesHit
pos = [0,0]
treesHit = 0
while pos[0] < 322:
pos[0]+=1
pos[1]+=5
pos[1] = pos[1] % 31
print(pos)
if path[pos[0]][pos[1]] == 1:
treesHit += 1
prdTrees *= treesHit
pos = [0,0]
treesHit = 0
while pos[0] < 322:
pos[0]+=1
pos[1]+=7
pos[1] = pos[1] % 31
print(pos)
if path[pos[0]][pos[1]] == 1:
treesHit += 1
prdTrees *= treesHit
pos = [0,0]
treesHit = 0
while pos[0] < 322:
pos[0]+=2
pos[1]+=1
pos[1] = pos[1] % 31
print(pos)
if path[pos[0]][pos[1]] == 1:
treesHit += 1
prdTrees *= treesHit
print(prdTrees)