Paste: aoc 2015 day 6 part 1

Author: chunes
Mode: factor
Date: Fri, 1 Sep 2023 19:10:26
Plain Text |
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 <zero-square-matrix> input [
    find-numbers unclip swap [ integer? ] filter first4
    swapd [ [a..b] ] 2bi@ rot
    '[ 2array _ run-command ] cartesian-each
] each concat sum .

New Annotation

Summary:
Author:
Mode:
Body: