Paste: AOC day 9

Author: chunes
Mode: factor
Date: Wed, 9 Dec 2020 15:55:11
Plain Text |
USING: assocs grouping io.encodings.ascii io.files kernel
literals math math.combinatorics math.parser math.ranges
math.statistics prettyprint sequences sets ;
IN: aoc.2020.09

<< CONSTANT: input $[ "input.txt" ascii file-lines [ dec> ] map ] >>

<< CONSTANT: part1 $[
    input dup 25 tail swap 25 <clumps> but-last-slice zip
    [ 2 [ sum ] map-combinations member? not ] assoc-find 2drop
] >>

CONSTANT: input2 $[ input ${ part1 } without ]

: find-range ( n -- seq )
    input2 swap <clumps> [ sum part1 = ] find nip ;

: part2 ( -- )
    input2 length [1,b] [ find-range ] find nip find-range
    minmax + . ;

New Annotation

Summary:
Author:
Mode:
Body: