USING: arrays grouping io io.encodings.utf8 io.files kernel math math.functions math.parser math.statistics math.vectors prettyprint sequences splitting strings ; IN: aoc.10 : input ( -- lines ) "~/factor/aoc/10/10.in" utf8 file-lines ; : I ( -- dts dxs ) input [ dup "noop" = [ drop { 0 1 } ] [ split-words last dec> 2 2array ] if ] map { 1 1 } prefix flip first2 swap [ rest ] [ but-last ] bi* ; : xs ( dts dxs -- seq ) cum-sum [ ] 2map concat ; CONSTANT: cycles { 20 60 100 140 180 220 } : part1 ( -- n ) I xs cycles 1 v-n swap nths cycles vdot ; : part2 ( -- ) I xs 40 group [ [ - [-1,1]? CHAR: # CHAR: . ? ] map-index >string print ] each ; : solve ( -- ) part1 . part2 ;