41 lines
772 B
Python
41 lines
772 B
Python
#!/usr/bin/python
|
|
|
|
fd = open("input", "r")
|
|
buf = []
|
|
lines = fd.readlines()
|
|
lenlines = len(lines)
|
|
|
|
for i in lines:
|
|
buf.append(i)
|
|
|
|
def counter(l, c):
|
|
cnt = 0
|
|
for i in l:
|
|
if i == c: cnt += 1
|
|
return cnt
|
|
|
|
def listmapper(l, x, y):
|
|
hlen = len(l[0]) - 1
|
|
return l[y][x % hlen]
|
|
print(x % hlen)
|
|
|
|
def getTrees(x, y):
|
|
try:
|
|
pos = (0, 0)
|
|
cnt = 0
|
|
while True:
|
|
pos = (pos[0] + x, pos[1] + y)
|
|
if listmapper(buf, pos[0], pos[1]) == '#': cnt += 1
|
|
except IndexError:
|
|
pass
|
|
return cnt
|
|
|
|
print(getTrees(3, 1))
|
|
print("--")
|
|
|
|
cnt = 1
|
|
for i in [[1, 1], [3, 1], [5, 1], [7, 1], [1, 2]]:
|
|
trees = getTrees(i[0], i[1])
|
|
cnt *= trees
|
|
print("{}, {} -- {} ({})".format(i[0], i[1], trees, cnt))
|