Paste: AOC 2022 day 2
Author: | zip |
Mode: | factor |
Date: | Fri, 2 Dec 2022 12:21:53 |
Plain Text |
IN: scratchpad "scratchpad" vocab-words [ see ] each
IN: scratchpad
SYMBOL: outcomemap inline
IN: scratchpad
SYMBOL: throwmap inline
USING: assocs namespaces sequences splitting ;
IN: scratchpad
: scorethrow ( string -- number )
" " split last scoremap get at ;
IN: scratchpad
SYMBOL: pointmap inline
USING: assocs sequences splitting ;
IN: scratchpad
: scoreoutcome2 ( string -- number )
" " split last H{ { "X" 0 } { "Y" 3 } { "Z" 6 } } at ;
USING: assocs namespaces ;
IN: scratchpad
: scorethrow2 ( string -- number )
throwmap get at pointmap get at ;
USING: assocs namespaces ;
IN: scratchpad
: scoreoutcome ( string -- number ) outcomemap get at ;
IN: scratchpad
SYMBOL: scoremap inline
USING: kernel math sequences ;
IN: scratchpad
: score ( array -- number )
[ [ scorethrow ] [ scoreoutcome ] bi + ] map sum ;
IN: scratchpad scoremap get .
H{ { "X" 1 } { "Y" 2 } { "Z" 3 } }
IN: scratchpad outcomemap get .
H{
{ "C X" 6 }
{ "C Z" 3 }
{ "B Z" 6 }
{ "B X" 0 }
{ "B Y" 3 }
{ "A Y" 6 }
{ "A X" 3 }
{ "C Y" 0 }
{ "A Z" 0 }
}
IN: scratchpad pointmap get .
H{ { "A" 1 } { "B" 2 } { "C" 3 } }
IN: scratchpad "scratchpad" about
IN: scratchpad throwmap get .
H{
{ "C X" "B" }
{ "C Z" "A" }
{ "B Z" "C" }
{ "B X" "A" }
{ "B Y" "B" }
{ "A Y" "A" }
{ "A X" "C" }
{ "C Y" "C" }
{ "A Z" "B" }
}
IN: scratchpad
New Annotation