USING: accessors combinators.short-circuit grouping io.encodings.utf8 io.files kernel math math.order math.parser sequences sequences.private sequences.snipped sequences.windowed.fixed splitting ; IN: aoc.2024.02 CONSTANT: input-file "vocab:aoc/2024/02/input.txt" : parsed-input ( -- input ) input-file utf8 file-lines [ " " split [ string>number ] map ] map ; : gradual? ( seq -- ? ) 2 [ first2 - abs 1 3 between? ] all? ; : strictly-monotonic? ( seq -- ? ) 2 [ first2 <=> ] map 2 [ first2 = ] all? ; : safe? ( seq -- ? ) { [ gradual? ] [ strictly-monotonic? ] } 1&& ; : part1 ( -- n ) parsed-input [ safe? ] count ; : safe-enough? ( seq -- ? ) [ length ] keep [ safe? ] curry any? ; : part2 ( -- n ) parsed-input [ safe-enough? ] count ;