Paste: AoC 2022 day 4

Author: zip
Mode: factor
Date: Sun, 4 Dec 2022 14:35:50
Plain Text |
! Copyright (C) 2022 Your name.
! See http://factorcode.org/license.txt for BSD license.
USING: io io.encodings.utf8 io.files ;
USING: hash-sets kernel math.parser ranges sequences sets splitting ;
IN: dec-4

: inrange? ( range range -- bool ) [ subset? ] [ swap subset? ] 2bi or ;

: line>ranges ( string -- range range ) "," split [ "-" split ] map concat [ string>number ] map first4 [ [a..b] >hash-set ] 2dip [a..b] >hash-set ;

: input ( -- array ) "/Users/zip/Desktop/aoc2022/dec-4/input.txt" utf8 file-lines ;

: part1 ( -- ) input [ line>ranges inrange? ] map sift length number>string print ;

: overlap? ( range range -- bool ) intersect null? not ;

: part2 ( -- ) input [ line>ranges overlap? ] map sift length number>string print ;

New Annotation

Summary:
Author:
Mode:
Body: