Paste: AoC Day 06

Author: CapitalEx
Mode: factor
Date: Tue, 6 Dec 2022 13:38:06
Plain Text |
USING: io.backend io.encodings.utf8 io.files kernel math
sequences sequences.windowed sets ;
IN: advent-of-code.day-06

: get-input-one ( -- seq )
    "vocab:advent-of-code/day-06/_input/one.txt" 
        normalize-path utf8 file-contents ;

: signal-start? ( string -- ? )
    dup length 4 < [ drop f ] [ all-unique? ] if ;

: start-location ( seq -- n )
    t swap index 1 + ;

: find-start ( length string -- n )
    [ signal-start? ] rolling-map start-location ;

: solve-part-one ( -- solution )
    get-input-one 4 find-start ;

: solve-part-two ( -- solution )
    get-input-one 14 find-start ;

New Annotation

Summary:
Author:
Mode:
Body: