From e491f7718e0055c6aac08b67d03685d35ea882e1 Mon Sep 17 00:00:00 2001 From: kwout Date: Sat, 3 Sep 2022 20:05:35 -0400 Subject: [PATCH] day 1, 2, 3a compelte --- day1/1a.py | 8 ++++++++ day1/1b.py | 11 +++++++++++ day2/2a.py | 15 +++++++++++++++ day2/2b.py | 18 ++++++++++++++++++ day3/3a.py | 26 ++++++++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 day1/1a.py create mode 100644 day1/1b.py create mode 100644 day2/2a.py create mode 100644 day2/2b.py create mode 100644 day3/3a.py diff --git a/day1/1a.py b/day1/1a.py new file mode 100644 index 0000000..480174b --- /dev/null +++ b/day1/1a.py @@ -0,0 +1,8 @@ +measures = [int(i) for i in open("input.txt", 'r').read().splitlines()] + +increases = 0 +for i in range(1,len(measures)): + if measures[i] > measures[i-1]: + increases += 1 + +print(increases) diff --git a/day1/1b.py b/day1/1b.py new file mode 100644 index 0000000..e92fa29 --- /dev/null +++ b/day1/1b.py @@ -0,0 +1,11 @@ +measures = [int(i) for i in open("input.txt", 'r').read().splitlines()] + +increases = 0 +old = measures[0]+measures[1]+measures[2] +for i in range(3,len(measures)): + new = measures[i] + measures[i-1] + measures[i-2] + if new > old: + increases += 1 + old = new + +print(increases) diff --git a/day2/2a.py b/day2/2a.py new file mode 100644 index 0000000..211e991 --- /dev/null +++ b/day2/2a.py @@ -0,0 +1,15 @@ +depth = 0 +forw = 0 + +for s in open("input.txt", 'r').read().splitlines(): + split = s.split() + match split[0]: + case "forward": + forw += int(split[1]) + case "down": + depth += int(split[1]) + case "up": + depth -= int(split[1]) + +print(depth*forw) + diff --git a/day2/2b.py b/day2/2b.py new file mode 100644 index 0000000..b1c7840 --- /dev/null +++ b/day2/2b.py @@ -0,0 +1,18 @@ +aim = 0 +depth = 0 +forw = 0 + +for s in open("input.txt", 'r').read().splitlines(): + split = s.split() + match split[0]: + case "forward": + i = int(split[1]) + forw += i + depth += aim * i + case "down": + aim += int(split[1]) + case "up": + aim -= int(split[1]) + +print(depth*forw) + diff --git a/day3/3a.py b/day3/3a.py new file mode 100644 index 0000000..64f9cbf --- /dev/null +++ b/day3/3a.py @@ -0,0 +1,26 @@ +lines = open("input.txt", 'r').read().splitlines() +leng = len(lines) +count = [0] * len(lines[0]) + +for s in lines: + for i in range(0, len(s)): + if bool(int(s[i])): + count[i] += 1 + +s = "" +t = "" +print(count) +for i in count: + if i > leng/2: + s += "1" + t += "0" + else: + s += "0" + t += "1" + +gama = int(s, 2) +epsi = int(t, 2) +print(gama) +print(epsi) +print(gama*epsi) +