Compare commits
2 Commits
12662b912c
...
b627e97c5a
Author | SHA1 | Date | |
---|---|---|---|
b627e97c5a | |||
893a8e3dbb |
42
2024/d2.py
Normal file
42
2024/d2.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from lib import get_data
|
||||||
|
from lib import ints
|
||||||
|
|
||||||
|
|
||||||
|
data = get_data(__file__)
|
||||||
|
|
||||||
|
s1 = 0
|
||||||
|
s2 = 0
|
||||||
|
|
||||||
|
for line in data.splitlines():
|
||||||
|
xs = ints(line)
|
||||||
|
|
||||||
|
deltas = []
|
||||||
|
for i in range(len(xs) - 1):
|
||||||
|
deltas.append(xs[i + 1] - xs[i])
|
||||||
|
if abs(xs[i + 1] - xs[i]) not in [1, 2, 3]:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if deltas[0] < 0 and all(deltas[i] < 0 for i in range(len(deltas))):
|
||||||
|
s1 += 1
|
||||||
|
elif deltas[0] > 0 and all(deltas[i] > 0 for i in range(len(deltas))):
|
||||||
|
s1 += 1
|
||||||
|
|
||||||
|
sublists = [xs[:i] + xs[i + 1 :] for i in range(len(xs))]
|
||||||
|
found = False
|
||||||
|
for xs in sublists:
|
||||||
|
deltas = []
|
||||||
|
for i in range(len(xs) - 1):
|
||||||
|
deltas.append(xs[i + 1] - xs[i])
|
||||||
|
if abs(xs[i + 1] - xs[i]) not in [1, 2, 3]:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if deltas[0] < 0 and all(deltas[i] < 0 for i in range(len(deltas))):
|
||||||
|
|
||||||
|
found = True
|
||||||
|
if deltas[0] > 0 and all(deltas[i] > 0 for i in range(len(deltas))):
|
||||||
|
found = True
|
||||||
|
if found:
|
||||||
|
s2 += 1
|
||||||
|
|
||||||
|
print(s1)
|
||||||
|
print(s2)
|
26
2024/d3.py
Normal file
26
2024/d3.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import re
|
||||||
|
from lib import get_data
|
||||||
|
from lib import ints
|
||||||
|
|
||||||
|
|
||||||
|
data = get_data(__file__)
|
||||||
|
|
||||||
|
t = 0
|
||||||
|
r = re.compile(r'mul\(\d+,\d+\)')
|
||||||
|
for match in r.findall(data):
|
||||||
|
a, b = ints(match)
|
||||||
|
t += a * b
|
||||||
|
print(t)
|
||||||
|
|
||||||
|
t = 0
|
||||||
|
enabled = True
|
||||||
|
for i in range(len(data.strip())):
|
||||||
|
m = r.match(data[i:])
|
||||||
|
if m and enabled:
|
||||||
|
a, b = ints(m.group())
|
||||||
|
t += a * b
|
||||||
|
elif data[i:].startswith("do()"):
|
||||||
|
enabled = True
|
||||||
|
elif data[i:].startswith("don't()"):
|
||||||
|
enabled = False
|
||||||
|
print(t)
|
@ -291,5 +291,8 @@ and focus. Of course, learning more algorithms and techniques helps.
|
|||||||
|
|
||||||
## AoC 2024
|
## AoC 2024
|
||||||
|
|
||||||
- Day 1: 1:30/2:49 (124th/141th)
|
- Day 1: `00:01:30 124 0 00:02:49 141 0`
|
||||||
- Day 2:
|
- Day 2: `00:05:34 686 0 00:08:21 531 0`
|
||||||
|
- Day 3: `00:01:48 165 0 00:02:40 56 45`
|
||||||
|
- Day 4:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user