Browse Source

Optimize day 3 a little

master
mid-kid 4 years ago
parent
commit
3d18482402
  1. 14
      d03.py

14
d03.py

@ -6,17 +6,13 @@ i = [x.strip() for x in open(argv[1])]
h = len(i) h = len(i)
w = len(i[0]) w = len(i[0])
def f(dx, dy):
def check(dx, dy): x = ok = 0
x = 0 for y in range(0, h, dy):
y = 0
ok = 0
while y < h:
if i[y][x%w] == "#": if i[y][x%w] == "#":
ok += 1 ok += 1
x += dx x += dx
y += dy
return ok return ok
print(check(3,1)) print(f(3,1))
print(check(1,1)*check(3,1)*check(5,1)*check(7,1)*check(1,2)) print(f(1,1)*f(3,1)*f(5,1)*f(7,1)*f(1,2))

Loading…
Cancel
Save