Paste: AoC 2022 day 6

Author: zip
Mode: factor
Date: Tue, 6 Dec 2022 11:00:14
Plain Text |
USING: arrays circular io.encodings.utf8 io.files kernel math
namespaces scratchpad sequences sets ;
FROM: namespaces => set ;
IN: dec-6

: input ( -- string ) "/Users/zip/desktop/aoc2022/dec-6/input.txt" utf8 file-lines first ;

: find-unique-n ( n string -- number ) swap f <array> <circular> marker set 0 [ marker get [ all-unique? not ] [ f swap in? ] bi or ] [ [ unclip marker get circular-push ] dip 1 + ] while nip ;

: part1 ( -- number ) 4 input find-unique-n ;

: part2 ( -- number ) 14 input find-unique-n ;

New Annotation

Summary:
Author:
Mode:
Body: