Paste: AOC day 13
Author: | chunes |
Mode: | factor |
Date: | Sun, 13 Dec 2020 21:40:16 |
Plain Text |
USING: fry io.encodings.ascii io.files kernel locals math
math.functions math.parser prettyprint sequences splitting ;
IN: aoc.2020.13
: wait ( depart id -- n ) tuck mod - ;
: part1 ( -- )
"input.txt" ascii file-lines first2
[ dec> ] dip ",x" split harvest [ dec> ] map
dupd [ wait ] with infimum-by [ wait ] keep * . ;
: next-fixed ( search fixed n index -- search fixed' )
'[ dup _ wait _ = ] [ over + ] until ;
:: find-time ( seq -- n )
seq unclip dup rot
[
1 + over integer?
[ over mod over :> n next-fixed [ n lcm ] dip ] [ 2drop ] if
] each-index nip ;
: part2 ( -- )
"input.txt" ascii file-lines second "," split [ dec> ] map
find-time . ;
New Annotation