Paste: AoC 2022 Day 10
Author: | Kacarott |
Mode: | factor |
Date: | Sat, 10 Dec 2022 09:42:15 |
Plain Text |
USING: kernel AOC prettyprint sequences splitting math
math.parser sequences.extras sequences.repeating
grouping io ;
IN: AOC.2022.10
: cycles ( insts -- seq ) V{ 1 } clone 1 rot [
dup first "noop" =
[ drop [ suffix! ] keep ]
[ second dec> [ [ suffix! ] keep ] dip + [ suffix! ] keep ]
if
] each drop ;
: signal-strength ( cycles -- result )
[ 19 f 40 ] dip <step-slice> [ 2 * 1 + 20 * * ] map-index sum ;
: pixels ( cycles -- drawing )
40 <iota> 240 cycle [ - abs 2 < CHAR: # CHAR: . ? ] 2map
40 <groups> "\n" join ;
: part-1 ( input -- result ) split-lines [ split-words ] map cycles signal-strength ;
: part-2 ( input -- result ) split-lines [ split-words ] map cycles pixels ;
MAIN: [ 10 read-day-input [ part-1 . ] [ part-2 print ] bi ]
New Annotation