Compare commits
6 commits
05c7b5bfb9
...
ca6047c747
| Author | SHA1 | Date | |
|---|---|---|---|
| ca6047c747 | |||
| cf3a9298d3 | |||
| 57ada9e80f | |||
| 6fd5f20d34 | |||
| b87c6ed284 | |||
| d08fab4101 |
3 changed files with 1 additions and 72 deletions
|
|
@ -1,31 +0,0 @@
|
||||||
from output import ints
|
|
||||||
|
|
||||||
|
|
||||||
def solve(data):
|
|
||||||
p1 = None
|
|
||||||
p2 = 0
|
|
||||||
ranges, ids = data.split("\n\n")
|
|
||||||
ids = ints(ids)
|
|
||||||
R = [ints(line) for line in ranges.split()]
|
|
||||||
p1 = sum(any(s <= n <= e for s, e in R) for n in ids)
|
|
||||||
c = 0
|
|
||||||
for s, e in sorted(R):
|
|
||||||
s = max(c + 1, s)
|
|
||||||
if s <= e:
|
|
||||||
p2 += e - s + 1
|
|
||||||
c = max(e, c)
|
|
||||||
|
|
||||||
return p1, p2
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
with open("./input/05.txt", "r") as f:
|
|
||||||
inp = f.read().strip()
|
|
||||||
|
|
||||||
p1, p2 = solve(inp)
|
|
||||||
|
|
||||||
print(p1)
|
|
||||||
print(p2)
|
|
||||||
|
|
||||||
assert p1 == 509
|
|
||||||
assert p2 == 336790092076620
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
import re
|
|
||||||
from math import prod
|
|
||||||
|
|
||||||
|
|
||||||
def solve(data):
|
|
||||||
p1 = 0
|
|
||||||
p2 = 0
|
|
||||||
rows = data.splitlines()
|
|
||||||
J = max(len(r) for r in rows) + 1
|
|
||||||
rows = [r.ljust(J) for r in rows]
|
|
||||||
ops = rows.pop()
|
|
||||||
s = 0
|
|
||||||
for ows in re.findall(r"(\S\s+)", ops):
|
|
||||||
o, *ws = ows
|
|
||||||
e = s + len(ws)
|
|
||||||
col = [ns for ns in [r[s:e] for r in rows]]
|
|
||||||
s += len(ows)
|
|
||||||
col1 = [int(r) for r in col]
|
|
||||||
col2 = [int("".join([nsc for nsc in ns if nsc.isdigit()])) for ns in zip(*col)]
|
|
||||||
match o:
|
|
||||||
case "*":
|
|
||||||
p1 += prod(col1)
|
|
||||||
p2 += prod(col2)
|
|
||||||
case "+":
|
|
||||||
p1 += sum(col1)
|
|
||||||
p2 += sum(col2)
|
|
||||||
return p1, p2
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
with open("./input/06.txt", "r") as f:
|
|
||||||
inp = f.read().strip()
|
|
||||||
|
|
||||||
p1, p2 = solve(inp)
|
|
||||||
|
|
||||||
print(p1)
|
|
||||||
print(p2)
|
|
||||||
|
|
||||||
assert p1 == 5524274308182
|
|
||||||
assert p2 == 8843673199391
|
|
||||||
|
|
@ -8,7 +8,7 @@ RUN pip install waitress==3.0.2
|
||||||
|
|
||||||
FROM reqs AS app
|
FROM reqs AS app
|
||||||
RUN mkdir /app/templates
|
RUN mkdir /app/templates
|
||||||
COPY templates/*.jinja2 /app/templates
|
COPY *.jinja2 /app/templates
|
||||||
COPY app.py app.py
|
COPY app.py app.py
|
||||||
|
|
||||||
ENV AOC_TOKEN=
|
ENV AOC_TOKEN=
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue