diff --git a/input/25.txt b/input/25.txt new file mode 100644 index 0000000..e14bdf9 --- /dev/null +++ b/input/25.txt @@ -0,0 +1,127 @@ +1---210=1=02-202 +2--200=0112- +112=2=200=02= +11-1 +1=1=112011=2=== +2-=11==1 +1==210-00=0= +1-2===-11--0-020 +111==121==-- +1-=2-11-112 +1=-10-10-11 +1=21101==100=0-01 +1222=0=22=1==1= +122-==-22 +2=-=02 +101-2-01 +122- +2=111-22-2=202-001 +1=1= +10=2 +2-22-0=20-11 +2=-22-10 +1=1 +10-==-=01202=0101 +121212101012=1 +1=2212=2-022021= +2=00=10--2-020-=20 +1-0222-22- +1=011 +1120--2-=1=22=1 +102==2----1 +11=1020=0--102==0- +12--0-11-21--1=2 +220-01010-111 +2=2=1=0=1-001-2 +1--0-= +1111-01 +1-2=-1=1221-00==1=1 +1-=0-00----022121=0= +2- +2-111200=2-12-0 +1002-002 +2020 +110=12==--1=12=2== +102-11122--0 +2=-=2-=1===11 +110=20 +2--12 +1=-2-1=01= +11122=211 +1-0002 +1==1=21011= +1=0-00122 +1---0112-=222 +2-222120=- +1000 +2-010=-0- +20=12000202221 +1120=2=21-2 +12==-1 +2=2==11=10=0 +1-0-001=-2 +20==2-02==--=101 +111001--20102 +121=21 +1=1-==2-=121 +10100==0= +2= +1=-0=20---=-02=1== +1-0=12=0=2=12 +21---2---2 +12=-=--=0 +2=002--=10 +1=1=-21==010=1-=2- +1=-10--= +20022-1---1-211 +1= +1-102==2=2000 +22-0222- +1120=1=202=0110-000 +220102==0- +10001=====1--1-=02 +2012-0=1=1=21210-2 +1-=1-0-0=- +21212-==01-1= +22222= +1--21==1-1-101-022 +111 +1-000212 +1-1=20= +1-21 +212====-1 +1== +2-===2-10=110= +1--22 +1=0-10010=12==100= +201- +1=1000220=12 +21--=-2 +10-0-200=1-0122 +2100222==20-=1-10 +100=11111121=1 +2110 +21201-1 +120=2-1--120001 +1==1=01100112 +11101 +1-=1=0 +2-=2 +10 +122=020221220-0 +2==21 +10=1011=1011 +11=02 +2210=---=0- +212 +2010-0202=22 +112-121111=2 +101112-0-1=00 +10==-=-20=-112===0 +1=0-10-0 +1=11-0=--110020= +20212--=-=01-11= +1==0-=0 +10-21010022110- +10--12=000 +10=0 diff --git a/src/25.rkt b/src/25.rkt new file mode 100644 index 0000000..71d06ab --- /dev/null +++ b/src/25.rkt @@ -0,0 +1,30 @@ +#lang racket + +(require "../lib.rkt") + +(define (snafu->number s) + (for/sum ([c (reverse (string->list s))] + [n (in-naturals)]) + (* (expt 5 n) + (match c + [#\= -2] + [#\- -1] + [_ (char->number c)])))) + +(define (number->snafu n) + (let loop ([n n] + [cs '()]) + (if (zero? n) (list->string cs) + (match (% n 5) + [4 (loop (/ (+ n 1) 5) (cons #\- cs))] + [3 (loop (/ (+ n 2) 5) (cons #\= cs))] + [2 (loop (/ (- n 2) 5) (cons #\2 cs))] + [1 (loop (/ (- n 1) 5) (cons #\1 cs))] + [0 (loop (/ n 5) (cons #\0 cs))])))) + +(define part1 + (number->snafu + (for/sum ([req (problem-input 25)]) + (snafu->number req)))) + +(show-solution part1 #f) \ No newline at end of file