Paste: AoC day 10
Author: | Garklein |
Mode: | factor |
Date: | Sat, 10 Dec 2022 13:55:22 |
Plain Text |
USING: arrays grouping io io.encodings.utf8 io.files kernel math
math.parser math.statistics math.vectors prettyprint sequences
sets 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 [ <repetition> ] 2map concat ;
CONSTANT: cycles { 20 60 100 140 180 220 }
: part1 ( -- n ) I xs cycles 1 v-n swap nths cycles v* sum ;
: part2 ( -- ) I xs 40 group [ [ - { 1 0 -1 } in? CHAR: # CHAR: . ? ] map-index >string print ] each ;
: solve ( -- ) part1 . part2 ;
Author: | Garklein |
Mode: | factor |
Date: | Sat, 10 Dec 2022 14:07:00 |
Plain Text |
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 [ <repetition> ] 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 ;
New Annotation