Paste: aoc14

Author: jonenst
Mode: factor
Date: Fri, 14 Dec 2018 11:05:11
Plain Text |
: newrecipes ( seq -- recipes )
sum number>string [ digit> ] { } map-as ; 
: add-recipes ( recipes pos -- recipes' pos' )
  2dup swap [ nth ] curry map [ newrecipes swap [ append! ] dip ]
  [ { 1 1 } v+ v+ over length [ mod ] curry map ] bi ;
 
:: aoc14-1 ( n -- tail )
V{ 3 7 } clone
{ 0 1 }
[ over length n 10 + >= ] [ add-recipes ] until drop 10 tail* [ >digit ] "" map-as  ;
:: aoc14-2 ( str -- n )
str [ digit> ] { } map-as :> scores
V{ 3 7 } clone
{ 0 1 }
[ over [ scores tail? ] [ but-last-slice scores tail? ] bi or ]
[ add-recipes ] until
drop dup but-last-slice scores tail? [ but-last ] when
length scores length - ;

New Annotation

Summary:
Author:
Mode:
Body: