! Copyright (C) 2022 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: combinators.short-circuit kernel math.intervals math.parser sequences splitting ; IN: 2022-aoc4 : parse-line ( string -- i1 i2 ) "," split1 [ "-" split1 [ dec> ] bi@ [a,b] ] bi@ ; : aoc4-1 ( string -- n ) split-lines [ parse-line { [ interval-subset? ] [ swap interval-subset? ] } 2|| ] count ; : aoc4-2 ( string -- n ) split-lines [ parse-line { [ intervals-intersect? ] [ swap intervals-intersect? ] } 2|| ] count ;