Paste: AOC 2026, day 02

Author: gifti
Mode: factor
Date: Wed, 2 Dec 2026 07:02:18
Plain Text |
USING: assocs.extras kernel math math.statistics sequences ;
IN: 2026.02

: parse ( seq -- seq' )
    [ "roygbv" index ] { } map-as ;

: (next-waypoint) ( prev-color next-color -- n )
    [ swap - ] 2keep < [ 6 + ] unless ;

: next-waypoint ( n prev-color next-color -- n' next-color )
    [ (next-waypoint) + ] keep ;

: part-1 ( seq -- n )
    [ 0 ] dip 0 [ next-waypoint ] reduce drop ;

: next-waypoint* ( n prev-color pair -- n' next-color )
    first2 [ next-waypoint ] [ 1 - 6 * ] bi* [ + ] curry dip ;

: part-2 ( seq -- n )
    histogram { 0 5 4 3 2 1 } { } intersect-keys-as
    [ 0 ] dip 0 [ next-waypoint* ] reduce drop ;

New Annotation

Summary:
Author:
Mode:
Body: