diff --git a/day1_2_refactor.py b/day1_2_refactor.py new file mode 100755 index 0000000..0b4045f --- /dev/null +++ b/day1_2_refactor.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import sys, utils + +def find_increasing_window(l: list): + win = l[:3] + count = 0 + for n in range(4, len(l)+1): + new_win = l[n-3:n] + if sum(new_win) > sum(win): + count += 1 + win = new_win + return count + +if __name__ == '__main__': + if len(sys.argv) < 2: + print("please supply input file") + sys.exit() + f = utils.File(sys.argv[1]) + print(find_increasing_window(f.get_ints())) + + diff --git a/day3_1.py b/day3_1.py index 122ec08..3a648e9 100755 --- a/day3_1.py +++ b/day3_1.py @@ -8,7 +8,6 @@ def power_consumption(l: list): def calculate_common(l: list): counter = [0 for _ in range(len(l[0]))] for line in l: - line = line.rstrip('\n') for i in range(len(line)): if line[i] == '1': counter[i] += 1 diff --git a/day5_2.py b/day5_2.py index 48e84a0..3df72f8 100755 --- a/day5_2.py +++ b/day5_2.py @@ -89,7 +89,7 @@ if __name__ == '__main__': m = Map(x, y) for x1, y1, x2, y2 in coords: m.add_line(x1, y1, x2, y2) - # print(m) + print(m) print(m.calculate_points(2)) diff --git a/utils.py b/utils.py index 8f64dfb..ef93da2 100644 --- a/utils.py +++ b/utils.py @@ -32,3 +32,6 @@ class File(object): self.lines = [] self.filename = '' + def len(self): + return len(self.lines) +