Paste: aoc8

Author: jonenst
Mode: factor
Date: Sat, 8 Dec 2018 07:25:09
Plain Text |
: ?nths ( indices seq -- vals )
[ 2dup bounds-check? [ nth ] [ 2drop 0 ] if ] curry map ;

: val ( node -- val )
  dup first empty? [ second sum ]
  [ [ first [ val ] map ] [ second [ 1 - ] map swap ?nths sum ] bi  ] if ;

: parse-it ( seq -- seq' parsed )
unclip-slice [ unclip-slice swap ] dip [ parse-it ] replicate 
-rot swap [ unclip-slice ] replicate swapd 2array ;

"/tmp/input" ascii file-lines first " " split
[ string>number ] map
parse-it nip
[ flatten sum . ] [ val . ] bi

New Annotation

Summary:
Author:
Mode:
Body: