Paste: aoc 4

Author: Kren/chunes
Mode: factor
Date: Sun, 4 Dec 2022 05:15:29
Plain Text |
USING: arrays io.encodings.ascii io.files kernel literals
math.intervals math.parser prettyprint sequences splitting ;
IN: aoc2022.day04

CONSTANT: input $[                                              ! parse as an assoc of intervals
    "vocab:aoc2022/day04/input.txt" ascii file-lines            ! { { [4,6] [8,10] } { [2,20] [5,15] } ... }
    [ "," split1 [ "-" split1 [ dec> ] bi@ [a,b] ] bi@ 2array ]
    map
]

: part1 ( -- )
    input [ [ first2 interval-intersect ] keep member? ] count . ;

: part2 ( -- )
    input [ first2 intervals-intersect? ] count . ;

: day04 ( -- ) part1 part2 ;

MAIN: day04

New Annotation

Summary:
Author:
Mode:
Body: