Paste: AOC day 2 simple
Author: | chunes |
Mode: | factor |
Date: | Wed, 2 Dec 2020 13:01:40 |
Plain Text |
USING: fry io.encodings.ascii io.files kernel literals math
math.order math.parser prettyprint sequences splitting ;
IN: aoc.2020.02simple
CONSTANT: input
$[ "resource:work/aoc/2020/02/input.txt" ascii file-lines ]
: parse ( str -- low high password char )
" -:" split harvest first4
[ [ string>number ] bi@ ] 2dip swap first ;
: valid1? ( str -- ? ) parse [ = ] curry count -rot between? ;
: valid2? ( str -- ? ) parse '[ 1 - _ nth _ = ] bi@ xor ;
: part1 ( -- ) input [ valid1? ] count . ;
: part2 ( -- ) input [ valid2? ] count . ;
New Annotation