USING: arrays combinators io.encodings.ascii io.files kernel literals math math.matrices pair-rocket prettyprint ranges sequences sorting.human ; IN: aoc.2015.day06 CONSTANT: input $[ "resource:work/aoc/2015/day06/input.txt" ascii file-lines ] : run-command ( matrix loc str -- matrix' ) { "turn off " => [ 0 swap pick matrix-set-nth ] "turn on " => [ 1 swap pick matrix-set-nth ] [ drop tuck over matrix-nth 1 = 0 1 ? rot pick matrix-set-nth ] } case ; 1000 input [ find-numbers unclip swap [ integer? ] filter first4 swapd [ [a..b] ] 2bi@ rot '[ 2array _ run-command ] cartesian-each ] each concat sum .