Paste: AoC 2025 day 7
| Author: | annikapaprika |
| Mode: | factor |
| Date: | Sun, 7 Dec 2025 16:16:42 |
Plain Text |
USING: arrays bit-arrays kernel math sequences sequences.extras
;
IN: 2025.07
: parse ( lines -- beams splitters-seq )
[ [ CHAR: . = not ] ?{ } map-as ] map unclip swap ;
: split-beams ( n beams splitters -- n' beams' )
[ [ length <bit-array> ] keep ] dip [
spin [
[
t swap [ 1 - ] [ 1 + ] bi 2array pick set-nths
[ 1 + ] dip
] [ t swap pick set-nth ] if
] [ 2drop ] if
] 2each-index ;
: part-1 ( beams splitters-seq -- n )
[ 0 ] 2dip [ split-beams ] each drop ;
: find-splitter ( col row splitters-seq -- col row' )
overd [ nth ] with find-from drop ;
MEMO: count-worlds ( col row splitters-seq -- n )
[ find-splitter ] keep
over [
[ [ 1 - ] 2dip count-worlds ]
[ [ 1 + ] 2dip count-worlds ] 3bi +
] [ 3drop 1 ] if ;
: part-2 ( beams splitters-seq -- n )
[ t ] [ index 0 ] [ count-worlds ] tri* ;
New Annotation