Paste: AoC 2022 Day 4

Author: nomennescio
Mode: factor
Date: Sun, 4 Dec 2022 05:37:20
Plain Text |
! 2022 nomennescio
USING: io.encodings.utf8 io.files kernel math.intervals math.parser prettyprint sequences splitting ;
IN: aoc2022

: parse-file ( path encoding -- pairs ) file-lines [ "," split [ "-" split [ dec> ] map first2 [a,b] ] map ] map ;
: part1 ( -- ) "input-4.txt" utf8 parse-file [ first2 [ interval-subset? ] [ swap interval-subset? ] 2bi or ] count . ;
: part2 ( -- ) "input-4.txt" utf8 parse-file [ first2 intervals-intersect? ] count . ;
: day4 ( -- ) part1 part2 ;

MAIN: day4

New Annotation

Summary:
Author:
Mode:
Body: