From 3d18482402803dd2e9dcae24293db5cc6167b198 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Sat, 5 Dec 2020 15:23:08 +0100 Subject: [PATCH] Optimize day 3 a little --- d03.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/d03.py b/d03.py index 15f4acc..bfc4f33 100755 --- a/d03.py +++ b/d03.py @@ -6,17 +6,13 @@ i = [x.strip() for x in open(argv[1])] h = len(i) w = len(i[0]) - -def check(dx, dy): - x = 0 - y = 0 - ok = 0 - while y < h: +def f(dx, dy): + x = ok = 0 + for y in range(0, h, dy): if i[y][x%w] == "#": ok += 1 x += dx - y += dy return ok -print(check(3,1)) -print(check(1,1)*check(3,1)*check(5,1)*check(7,1)*check(1,2)) +print(f(3,1)) +print(f(1,1)*f(3,1)*f(5,1)*f(7,1)*f(1,2))