Paste: aoc3
Author: | erg |
Mode: | factor |
Date: | Sat, 3 Dec 2022 05:13:34 |
Plain Text |
USING: kernel math sequences sets splitting ;
IN: 2022-aoc3
: score ( n -- n' )
dup CHAR: a >= [
CHAR: a - 1 +
] [
CHAR: A - 1 + 26 +
] if ;
: process-line ( string -- n )
dup length 2 /i cut
intersect [ score ] map sum ;
: aoc3-1 ( string -- n )
split-lines 0 [ process-line + ] reduce ;
: process-lines ( strings -- n )
first3 intersect intersect [ score ] map sum ;
: aoc3-2 ( string -- n )
split-lines 3 group 0 [ process-lines + ] reduce ;
New Annotation