diff options
| author | nekineki <nekineki@nekineki.net> | 2022-12-25 07:23:55 +0100 |
|---|---|---|
| committer | nekineki <nekineki@nekineki.net> | 2022-12-25 07:23:55 +0100 |
| commit | edc8466e498370dec425379915b83df49de5c88d (patch) | |
| tree | 7428b01632a1fdc03415c6fcee455520d72e71ee /2022 | |
| parent | 1addc1ee10820384de416d30a0b9be595f7dc648 (diff) | |
day25
Diffstat (limited to '2022')
| -rwxr-xr-x | 2022/day25.py | 53 | ||||
| -rw-r--r-- | 2022/in/day25.pzl | 107 | ||||
| -rw-r--r-- | 2022/in/day25.ref | 13 |
3 files changed, 173 insertions, 0 deletions
diff --git a/2022/day25.py b/2022/day25.py new file mode 100755 index 0000000..b608ca5 --- /dev/null +++ b/2022/day25.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +# import numpy as np +from functools import reduce +from re import findall +from copy import deepcopy +import sys + +# filename = "in/day25.ref" +filename = "in/day25.pzl" +data = open(filename).read() +lines = [line for line in data.rstrip('\n').split('\n')] +# print(lines) + +res1 = 0 +res2 = 0 + +def from_snafu(s): + val = 0 + for char in s: + val *= 5 + if char == '0': + pass + elif char == '1': + val += 1 + elif char == '2': + val += 2 + elif char == '-': + val -= 1 + elif char == '=': + val -= 2 + return val + +def to_snafu(n): + # conv = ['00', '01', '02', '1=', '1-', '10', '11', '12', '2=', '2-'] + conv = ['=', '-', '0', '1', '2'] + if -2 <= n <= 2: + return conv[n+2] + else: + if -2 <= n%5 <= 2: + return to_snafu(n//5) + conv[n%5 - 3] + elif 2 < n%5: + return to_snafu(n//5 + 1) + conv[n%5 - 3] + +res1_dec = 0 +for line in lines: + res1_dec += from_snafu(line) + +res1 = to_snafu(res1_dec) + +print('res1:', res1) +print('res2:', res2) + diff --git a/2022/in/day25.pzl b/2022/in/day25.pzl new file mode 100644 index 0000000..ac24512 --- /dev/null +++ b/2022/in/day25.pzl @@ -0,0 +1,107 @@ +21211-122 +1=--02-10=-=00=-0 +1=-2 +1-1-1-===2=0--1- +1211= +1=22=-= +1-0-=0210 +2-0-02 +1=1--1=-0210---=-1 +200-0=02--2 +20112=02 +1201--=-022 +1-100== +1- +1=-1=22===200101-2 +1==0010221-=22--0-02 +1002=11022 +1=02 +222=---112-=21=02= +21==10--=01-1-=1 +1===--11=102 +2==2=0022=1=102 +101221=-2-=-00-12 +10=12220==--- +1-2 +2--01112 +11=01-=1002- +1==-00-=10 +10=2==-= +10-1=-=20-2-= +1=1 +2120- +2-2-=-0==- +1-2-22=001-=-000 +21222-2222=102-2-- +101010 +1=0110 +1-21 +10 +1=022==2- +102-21==010 +20=-2- +1==-== +1=-0212===101 +111202220=12-1-=-2 +1-11110-==0=0-0=2 +2=2-0=0=02-2=-0-0=0 +10=22=11-1-1-21-021 +1212 +20=1=00202-==2-- +1==2 +100-- +122=- +2=220010 +202-222=212100-110 +20021=222==1--==-= +1==2212=- +1=-11--221===1== +21=21021-=1 +2- +11=02-=-----1=0= +10=2-00200 +111- +12=1=12121==-=-=- +1==0- +2--2-0=0-=2=21 +1==02-0=022-1=2- +1-112 +1--01--2=2= +221=1=20-=0-== +1=2-0-21-- +1=11 +1120-=00-==2= +1-=1-02101-02 +221-1= +1---=-=1211 +22= +221-=21=2010 +2-2102= +2--121=11-011 +1-1-01-1=2=001 +2-=-=22-=01-- +1-0=20=22 +2002122211=02 +1-2-21-21211012= +2=0200201= +2=-102- +1==202=-2==1= +1=0=010120= +2==1100-01==-0 +1220112102111=0 +1=10=1-=-2= +1=-200020=-1001 +11=11-=2 +1==01=11=0=2-2== +2=0-0-1=11-222= +1221=0-1= +1-=1-022 +10-1=22---021=1 +1011-1-=22-12 +1=0-122=-1== +2111-0=20= +1==01100-= +200111102 +12=0-2=2112--121=1 +2=01 +1==221=2211--2011 diff --git a/2022/in/day25.ref b/2022/in/day25.ref new file mode 100644 index 0000000..027aeec --- /dev/null +++ b/2022/in/day25.ref @@ -0,0 +1,13 @@ +1=-0-2 +12111 +2=0= +21 +2=01 +111 +20012 +112 +1=-1= +1-12 +12 +1= +122 |
