Paste: AoC day 2
Author: | Kren/chunes |
Mode: | factor |
Date: | Fri, 2 Dec 2022 06:43:07 |
Plain Text |
USING: assocs io.encodings.ascii io.files kernel literals math
pair-rocket prettyprint sequences ;
IN: aoc2022.day02
CONSTANT: input $[
"resource:work/aoc2022/day02/input.txt" ascii file-lines
]
CONSTANT: scores {
"A Y" => 6 "B Z" => 6 "C X" => 6
"A X" => 3 "B Y" => 3 "C Z" => 3
"A Z" => 0 "B X" => 0 "C Y" => 0
}
: score ( seq -- n )
dup [ last 87 - ] map-sum swap scores substitute sum + ;
: part1 ( -- ) input score . ;
: outcomes>reactions ( seq -- newseq )
{
"A X" => "A Z" "A Y" => "A X" "A Z" => "A Y"
"C X" => "C Y" "C Y" => "C Z" "C Z" => "C X"
} substitute ;
: part2 ( -- ) input outcomes>reactions score . ;
: day02 ( -- ) part1 part2 ;
MAIN: day02
New Annotation