Do day 1 and 2.
This commit is contained in:
5
README.md
Normal file
5
README.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Times
|
||||||
|
|
||||||
|
- Day 1: 7:52 ... so slow brah :/ top 100 required 2:05...
|
||||||
|
- Day 2: 22:30 ... I mistyped the first and second was just bad top 100 would have been 6:16 (doable?)
|
||||||
|
- Day 3:
|
||||||
64
d1.py
Normal file
64
d1.py
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
EXAMPLE = """
|
||||||
|
1000
|
||||||
|
2000
|
||||||
|
3000
|
||||||
|
|
||||||
|
4000
|
||||||
|
|
||||||
|
5000
|
||||||
|
6000
|
||||||
|
|
||||||
|
7000
|
||||||
|
8000
|
||||||
|
9000
|
||||||
|
|
||||||
|
10000
|
||||||
|
"""
|
||||||
|
|
||||||
|
def solve(lines: list[str]):
|
||||||
|
counter = 0
|
||||||
|
count_max = 0
|
||||||
|
for line in lines.splitlines():
|
||||||
|
if line.strip() == "":
|
||||||
|
if counter >= count_max:
|
||||||
|
count_max = counter
|
||||||
|
counter = 0
|
||||||
|
else:
|
||||||
|
counter += int(line)
|
||||||
|
return count_max
|
||||||
|
|
||||||
|
def solve2(lines: list[str]):
|
||||||
|
counter = 0
|
||||||
|
count_max = 0
|
||||||
|
counts = []
|
||||||
|
for line in lines.splitlines():
|
||||||
|
if line.strip() == "":
|
||||||
|
if counter >= count_max:
|
||||||
|
count_max = counter
|
||||||
|
counts.append(counter)
|
||||||
|
counter = 0
|
||||||
|
else:
|
||||||
|
counter += int(line)
|
||||||
|
counts.append(counter)
|
||||||
|
|
||||||
|
counts.sort(reverse=True)
|
||||||
|
return sum(counts[:3])
|
||||||
|
|
||||||
|
def main():
|
||||||
|
example = str(EXAMPLE)
|
||||||
|
print("Example 1:", solve(example))
|
||||||
|
|
||||||
|
data = open("i1.txt").read()
|
||||||
|
print("Solution 1:", solve(data))
|
||||||
|
|
||||||
|
example = str(EXAMPLE)
|
||||||
|
print("Example 2:", solve2(example))
|
||||||
|
|
||||||
|
data = open("i1.txt").read()
|
||||||
|
print("Solution 2:", solve2(data))
|
||||||
|
return
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
96
d2.py
Normal file
96
d2.py
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
EXAMPLE = """
|
||||||
|
A Y
|
||||||
|
B X
|
||||||
|
C Z
|
||||||
|
"""
|
||||||
|
|
||||||
|
def clean(text: str) -> list[str]:
|
||||||
|
return list(filter(lambda l: l.strip() != "", text.splitlines()))
|
||||||
|
# return list(text.splitlines()))
|
||||||
|
|
||||||
|
def solve(lines: list[str]):
|
||||||
|
s = 0
|
||||||
|
for (i, line) in enumerate(lines):
|
||||||
|
a, b = line.split(" ")
|
||||||
|
if b == "X":
|
||||||
|
s += 1
|
||||||
|
if a == "A":
|
||||||
|
s += 3
|
||||||
|
elif a == "B":
|
||||||
|
s += 0
|
||||||
|
elif a == "C":
|
||||||
|
s += 6
|
||||||
|
else:
|
||||||
|
print("invalid")
|
||||||
|
elif b == "Y":
|
||||||
|
s += 2
|
||||||
|
if a == "A":
|
||||||
|
s += 6
|
||||||
|
elif a == "B":
|
||||||
|
s += 3
|
||||||
|
elif a == "C":
|
||||||
|
s += 0
|
||||||
|
else:
|
||||||
|
print("invalid")
|
||||||
|
elif b == "Z":
|
||||||
|
s += 3
|
||||||
|
if a == "A":
|
||||||
|
s += 0
|
||||||
|
elif a == "B":
|
||||||
|
s += 6
|
||||||
|
elif a == "C":
|
||||||
|
s += 3
|
||||||
|
else:
|
||||||
|
print("invalid")
|
||||||
|
return s
|
||||||
|
|
||||||
|
def solve2(lines: list[str]):
|
||||||
|
s = 0
|
||||||
|
for (i, line) in enumerate(lines):
|
||||||
|
a, b = line.split(" ")
|
||||||
|
if a == "A":
|
||||||
|
if b == "X": # lose
|
||||||
|
s += 3
|
||||||
|
elif b == "Y": # draw
|
||||||
|
s += 4
|
||||||
|
elif b == "Z": # win
|
||||||
|
s += 8
|
||||||
|
else:
|
||||||
|
print("invalid")
|
||||||
|
elif a == "B":
|
||||||
|
if b == "X": # lose
|
||||||
|
s += 1
|
||||||
|
elif b == "Y": # draw
|
||||||
|
s += 5
|
||||||
|
elif b == "Z": # win
|
||||||
|
s += 9
|
||||||
|
else:
|
||||||
|
print("invalid")
|
||||||
|
elif a == "C":
|
||||||
|
if b == "X": # lose
|
||||||
|
s += 2
|
||||||
|
elif b == "Y": # draw
|
||||||
|
s += 6
|
||||||
|
elif b == "Z": # win
|
||||||
|
s += 7
|
||||||
|
else:
|
||||||
|
print("invalid")
|
||||||
|
return s
|
||||||
|
|
||||||
|
def main():
|
||||||
|
example = clean(EXAMPLE)
|
||||||
|
print("Example 1:", solve(example))
|
||||||
|
|
||||||
|
data = clean(open("i2.txt").read())
|
||||||
|
print("Solution 1:", solve(data))
|
||||||
|
|
||||||
|
example = clean(EXAMPLE)
|
||||||
|
print("Example 2:", solve2(example))
|
||||||
|
|
||||||
|
data = clean(open("i2.txt").read())
|
||||||
|
print("Solution 2:", solve2(data))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
40
d3.py
Normal file
40
d3.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
EXAMPLE = """
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def clean(text: str) -> list[str]:
|
||||||
|
return list(filter(lambda l: l.strip() != "", text.splitlines()))
|
||||||
|
|
||||||
|
def solve(lines: list[str]):
|
||||||
|
s = 0
|
||||||
|
for (i, line) in enumerate(lines):
|
||||||
|
print(i, line)
|
||||||
|
return s
|
||||||
|
|
||||||
|
def solve2(lines: list[str]):
|
||||||
|
s = 0
|
||||||
|
for (i, line) in enumerate(lines):
|
||||||
|
print(i, line)
|
||||||
|
return s
|
||||||
|
|
||||||
|
def main():
|
||||||
|
example = clean(EXAMPLE)
|
||||||
|
print("Example 1:", solve(example))
|
||||||
|
return
|
||||||
|
|
||||||
|
data = clean(open("i3.txt").read())
|
||||||
|
print("Solution 1:", solve(data))
|
||||||
|
return
|
||||||
|
|
||||||
|
example = clean(EXAMPLE)
|
||||||
|
print("Example 2:", solve2(example))
|
||||||
|
return
|
||||||
|
|
||||||
|
data = clean(open("i3.txt").read())
|
||||||
|
print("Solution 2:", solve2(data))
|
||||||
|
return
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user