From a3d2b5140f712496e01f7bdfa8b6b1129344e64c Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Thu, 3 Dec 2020 11:00:59 +0100 Subject: [PATCH] better (and faster) solution --- day03.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) mode change 100644 => 100755 day03.py diff --git a/day03.py b/day03.py old mode 100644 new mode 100755 index 4b8bd99..78a6344 --- a/day03.py +++ b/day03.py @@ -8,19 +8,13 @@ def check_for_trees(right_step, down_step, treelines): x = 0 y = 0 tree_count = 0 - for treeline in treelines: - if y % down_step != 0: - y = y + 1 - continue - - while len(treeline) < x + 1: - treeline = treeline + treeline - - if treeline[x] == '#': + maxX = len(treelines[0]) + while y < len(treelines): + if treelines[y][x] == '#': tree_count = tree_count + 1 - x = x + right_step - y = y + 1 + y = y + down_step + x = (x + right_step) % maxX return tree_count