Paste: AoC day 6

Author: Garklein
Mode: factor
Date: Tue, 6 Dec 2022 23:16:26
Plain Text |
USING: io.encodings.utf8 io.files kernel math prettyprint
sequences sets ;
IN: aoc.6

: input ( -- input ) "~/factor/aoc/6/6.in" utf8 file-lines first ;

: find-start ( str n-uniq -- n ) [ dupd [ dupd head all-unique? ] curry [ rest ] until [ length ] bi@ - ] keep + ;
: part1 ( -- n ) input 4  find-start ;
: part2 ( -- n ) input 14 find-start ;

: solve ( -- ) part1 . part2 . ;

Annotation: Refactor after learning about `clump`

Author: Garklein
Mode: factor
Date: Tue, 6 Dec 2022 23:22:30
Plain Text |
USING: io.encodings.utf8 io.files kernel math prettyprint
sequences sets ;
IN: aoc.6

: input ( -- input ) "~/factor/aoc/6/6.in" utf8 file-lines first ;

: find-start ( str n-uniq -- n ) [ clump [ all-unique? ] find drop ] keep + ;
: part1 ( -- n ) input 4  find-start ;
: part2 ( -- n ) input 14 find-start ;

: solve ( -- ) part1 . part2 . ;

New Annotation

Summary:
Author:
Mode:
Body: