diff --git a/day25.py b/day25.py new file mode 100644 index 0000000..113e981 --- /dev/null +++ b/day25.py @@ -0,0 +1,58 @@ +from tools.aoc import AOCDay +from typing import Any + + +def int2snafu(dec: int) -> str: + conv = "012=-0" + snafu = "" + power = 1 + over = 0 + while dec > 0: + c = dec % (5 ** power) + over + dec //= 5 + if c > 2: + over = 1 + else: + over = 0 + + snafu = conv[c] + snafu + + return snafu + + +def snafu2int(snafu: str) -> int: + dec = 0 + for i, c in enumerate(snafu): + if c == '-': + val = -1 + elif c == '=': + val = -2 + else: + val = int(c) + + dec += 5 ** (len(snafu) - i - 1) * val + + return dec + + +class Day(AOCDay): + inputs = [ + [ + ("2=-1=0", "input25_test"), + ("2==221=-002=0-02-000", "input25"), + ], + [ + (None, "input25"), + ] + ] + + def part1(self) -> Any: + return int2snafu(sum(snafu2int(c) for c in self.getInput())) + + def part2(self) -> Any: + return "" + + +if __name__ == '__main__': + day = Day(2022, 25) + day.run(verbose=True) diff --git a/inputs/input25 b/inputs/input25 new file mode 100644 index 0000000..fae5f5b --- /dev/null +++ b/inputs/input25 @@ -0,0 +1,101 @@ +22-00====1 +1210=012020-1= +2=-221 +1=020 +1=2=0==12----=- +1===-22-= +101120212112- +2022-==20-=-12===2 +1=20-200=22-1-1-2= +1-20021=21- +11--0-==0-1-22 +2--0=---2=- +21=--=-01=-0=112-21 +2=0200 +1011021--0-=-10010 +2=1=122-22=1---2 +110-0--0 +200 +1=2 +1==11=101-=-000=0==2 +1200-022-= +1--0=02-2=21220022 +10-- +10===202=22=00=1 +11022 +1--222-- +100 +2-0 +1=221== +1==21=22 +2==0-=2 +1==1=21=201- +12-0=1110-1=02-022 +2-12=21=--0020= +10-1-0=0=01=0--=2-- +2=1==-001=0=12 +212=10002 +10-=02200202=2== +1-21-0=-10 +1-=12222112 +1=1--12220=1 +10- +1=-02 +1=210 +21==1= +1--==--11 +1--21212-=--200-0- +1000010 +202=012-11-100200 +2=-21202200-= +11=1112=1020111 +12=1002022-0 +1122 +1=-0- +1=1=20=0010- +12=2-0000--- +1- +2-2= +12001==---1 +2---=--=0012121100 +10-10-11=1 +1=112-2=0-0=0--=0 +2=0=212122 +102==21101=-==1 +102 +1=2-2-0000211 +10-120-=00 +2=-02112010111-0- +1-0= +112 +1=2= +11=20 +10-2-01-210 +1-02122-2=- +1-22==0===0-0 +10=--=011- +2101-=1-12 +1==0=0=01 +22110-=0=111 +12---1-10-0-=1 +2-2-= +1-=101--11=12= +2-0--02-01=1-10== +2=--=200=12=110 +12= +2--= +20212 +2102-2 +2=202102 +2=1= +1101011-=1222- +11 +202 +102=10001= +101001 +1====11=0=12 +2211001 +11-2- +1-00 +11=1-1-- +2= diff --git a/inputs/input25_test b/inputs/input25_test new file mode 100644 index 0000000..237ef0c --- /dev/null +++ b/inputs/input25_test @@ -0,0 +1,13 @@ +1=-0-2 +12111 +2=0= +21 +2=01 +111 +20012 +112 +1=-1= +1-12 +12 +1= +122 \ No newline at end of file