Paste: aoc08
Author: | jon |
Mode: | factor |
Date: | Fri, 8 Dec 2017 15:53:19 |
Plain Text |
USING: assocs combinators io.encodings.ascii io.files kernel
math math.parser sequences splitting ;
IN: aoc.2017.08
: conditionok?
swap 4 tail
[ first swap at 0 or ] [ third string>number ] [ second ] tri
{
{ "<" [ < ] }
{ ">" [ > ] }
{ "<=" [ <= ] }
{ ">=" [ >= ] }
{ "==" [ = ] }
{ "!=" [ = not ] }
} case ;
SYMBOL: maxreg
: (do-insn)
[ 0 or ] dip
[ third string>number ] [ second "inc" = ] bi
[ + ] [ - ] if
dup maxreg get 0 or > [ dup maxreg set ] when ;
: do-insn
[ " " split ] dip
2dup conditionok? [
over [ first ] 2dip [ (do-insn) ] curry change-at
] [ 2drop ] if ;
: p1
"/tmp/input" ascii file-lines
H{ } clone [
[ do-insn ] curry each
] keep values supremum ;
: p2
0 maxreg [ p1 drop maxreg get ] with-variable ;
New Annotation