! Copyright (C) 2022 Keldan Chapman. ! See http://factorcode.org/license.txt for BSD license. 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 [ 2 * 1 + 20 * * ] map-index sum ; : pixels ( cycles -- drawing ) 40 240 cycle [ - abs 2 < CHAR: # CHAR: . ? ] 2map 40 "\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 ]