day25 finished
This commit is contained in:
parent
c2ebf9dc84
commit
56764331a4
6 changed files with 247 additions and 25 deletions
0
advent/days/day25/__init__.py
Normal file
0
advent/days/day25/__init__.py
Normal file
13
advent/days/day25/data/example01.txt
Normal file
13
advent/days/day25/data/example01.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
1=-0-2
|
||||
12111
|
||||
2=0=
|
||||
21
|
||||
2=01
|
||||
111
|
||||
20012
|
||||
112
|
||||
1=-1=
|
||||
1-12
|
||||
12
|
||||
1=
|
||||
122
|
||||
143
advent/days/day25/data/input.txt
Normal file
143
advent/days/day25/data/input.txt
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
1=0=01=0=2111-1211
|
||||
1==21=
|
||||
20--
|
||||
1-=1200=-=0
|
||||
211==12=2=0111==
|
||||
2=-10
|
||||
1221=221=0-1=-
|
||||
12=02=-12020=12=01-
|
||||
12112101
|
||||
20
|
||||
120120=21=1002-1
|
||||
10==1-02=1
|
||||
1=11200001-=--
|
||||
1=222-1=012=2
|
||||
20===1-1102-=
|
||||
1020
|
||||
102=-==-=2-
|
||||
112-2112-00012-
|
||||
1010=--121
|
||||
202022=-=2-22=
|
||||
122==1=1020011=-00
|
||||
10212==-0
|
||||
2=--12020=1-0=-2=-
|
||||
1110-1-2
|
||||
20==210221=-21--12
|
||||
1=-02--=22=-122
|
||||
2=-=0=00=1--1-2=--
|
||||
2==2==2-
|
||||
2=12=1
|
||||
2=01=
|
||||
202=20202-000
|
||||
1=0-=020021022012
|
||||
2=0-011-=2=-0-=21
|
||||
1=211
|
||||
1-=1=11=--010=---
|
||||
1000020-12==
|
||||
2-=122-1211-0=
|
||||
10=2220122012
|
||||
2=21-01=212
|
||||
10111==2=2-12
|
||||
111
|
||||
1=2---2211=2011=--
|
||||
1--=0000=1-020
|
||||
2=02-=-
|
||||
1-011=
|
||||
12020-0=-1-220100
|
||||
2-==000=21=1
|
||||
2-0100000-12-2-=
|
||||
1-=1
|
||||
1221=2-1==02-=202
|
||||
200
|
||||
122-2-0
|
||||
10=2101-22
|
||||
1==-120-1
|
||||
2=2=2=-11--==-==
|
||||
2111-=2=-=-2
|
||||
1--
|
||||
1-0=10-0112-12=
|
||||
10=
|
||||
2=01=1=-=20=
|
||||
1=
|
||||
1211-2=-1=
|
||||
222=
|
||||
122=2-1-0
|
||||
1-2=20-=02122-1
|
||||
1==-=2===0-=1100--11
|
||||
12-0=201=10=-=
|
||||
1=01=2=22-2-1-1
|
||||
120==222100=0
|
||||
11=-=--12=2-1101
|
||||
102=1221=---0==021
|
||||
2-=-2=202-=-==
|
||||
100=1=02020-221=
|
||||
1=0=-220=
|
||||
1001-
|
||||
20==2==1-1
|
||||
1=2-2=2=-12=
|
||||
10=0--2
|
||||
10-202-2002=22=
|
||||
2=2=
|
||||
1-011=0=-12---
|
||||
1002220
|
||||
2=
|
||||
1--=2---111
|
||||
222==2
|
||||
11100
|
||||
1=0=201
|
||||
1--02-
|
||||
1=11-==0=021
|
||||
1-=00=
|
||||
1==12-20-=002001=
|
||||
1=0=-=21-
|
||||
1000-1=0-0=1=01-2-
|
||||
2==
|
||||
1-0
|
||||
1=101-0-1
|
||||
1=0=
|
||||
11=2==-0-2202-0=
|
||||
10-0=0=1-002
|
||||
1-=0210=01120-
|
||||
1112=2-0-2=-01
|
||||
1-1=022=21
|
||||
2=1-2--120
|
||||
10002--0=220-0-2=12
|
||||
11002102100
|
||||
11000-2-12
|
||||
120=-==1-2-=
|
||||
21
|
||||
11
|
||||
2=121-
|
||||
1==
|
||||
1=-
|
||||
1-=--2=-
|
||||
2=-10-=0
|
||||
2200-1-
|
||||
2=21-1200==
|
||||
1-102210=002=--112
|
||||
1-10
|
||||
122=202=201-=-10-1
|
||||
2212121=02102
|
||||
21=2-211=-1-20-
|
||||
101-=01-1
|
||||
200012112=
|
||||
22=21201=22
|
||||
1-1212=1-=1
|
||||
1212-==1=01
|
||||
22==--=
|
||||
1=-2-1-==020-10-=
|
||||
1=1210=--00
|
||||
1=--=1=
|
||||
2010111-00111-2=2
|
||||
11=21-0=2-01
|
||||
21=
|
||||
1=-0-220
|
||||
102-=0
|
||||
1=---0-
|
||||
1-1122-=121222--0
|
||||
10110=1-20--1-1
|
||||
20=--21220-=
|
||||
1=---22-
|
||||
2-000===1101=
|
||||
20-
|
||||
10==
|
||||
33
advent/days/day25/solution.py
Normal file
33
advent/days/day25/solution.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Iterator
|
||||
|
||||
day_num = 25
|
||||
|
||||
|
||||
def part1(lines: Iterator[str]) -> str:
|
||||
snafu = sum(from_snafu(line) for line in lines)
|
||||
return to_snafu(snafu)
|
||||
|
||||
|
||||
def part2(lines: Iterator[str]) -> None:
|
||||
return None
|
||||
|
||||
|
||||
SNAFU = "=-012"
|
||||
|
||||
|
||||
def from_snafu(line: str) -> int:
|
||||
result = 0
|
||||
for char in line:
|
||||
result = result * 5 + SNAFU.index(char) - 2
|
||||
return result
|
||||
|
||||
|
||||
def to_snafu(number: int) -> str:
|
||||
result = ""
|
||||
while number > 0:
|
||||
mod = (number + 2) % 5
|
||||
result = SNAFU[mod] + result
|
||||
number = (number - mod + 2) // 5
|
||||
return result
|
||||
31
advent/days/day25/test_solution.py
Normal file
31
advent/days/day25/test_solution.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from advent.common import input
|
||||
|
||||
from .solution import day_num, part1, part2, from_snafu, to_snafu
|
||||
|
||||
|
||||
def test_part1():
|
||||
lines = input.read_lines(day_num, 'example01.txt')
|
||||
expected = "2=-1=0"
|
||||
result = part1(lines)
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_part2():
|
||||
lines = input.read_lines(day_num, 'example01.txt')
|
||||
expected = None
|
||||
result = part2(lines)
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_976():
|
||||
input = "2=-01"
|
||||
expected = 976
|
||||
result = from_snafu(input)
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_4890():
|
||||
input = 4890
|
||||
expected = "2=-1=0"
|
||||
result = to_snafu(input)
|
||||
assert result == expected
|
||||
Loading…
Add table
Add a link
Reference in a new issue