Paste: AOC 2024 11
Author: | IF TARMO SEES THIS VI VON |
Mode: | factor |
Date: | Wed, 11 Dec 2024 22:33:51 |
Plain Text |
USING: io.encodings.ascii math.functions math.parser splitting ;
: read-file ( path -- numbers ) ascii file-lines first " " split harvest [ string>number ] map ;
: num-digits ( number -- digits ) log10 >integer 1 + ;
MEMO: blink ( r s -- ns ) swap dup 0 > [ 1 - swap {
{ [ dup 0 eq? ]
[ drop 1 blink ] }
{ [ dup num-digits even? ]
[ dup num-digits 2 / 10 swap ^ [ / >bignum ] [ mod ] 2bi overd [ blink ] 2bi@ + ] }
[ 2024 * blink ]
} cond ] [ 2drop 1 ] if ;
: p1 ( path -- ) read-file [ 25 swap blink ] map-sum . ;
: p2 ( path -- ) read-file [ 75 swap blink ] map-sum . ;
New Annotation