Paste: AOC day 15 alternate

Author: chunes
Mode: factor
Date: Tue, 15 Dec 2020 07:46:50
Plain Text |
USING: assocs fry kernel make math namespaces prettyprint
sequences ;
IN: aoc.2020.15alt

: play-game ( seq n -- seq )
    [
        over length - swap dup % <enumerated> [ first2 swap ] H{ } map>assoc
        '[
            building get [ length 1 - ] [ last ] bi _ 3dup
            2dup key? [ at - ] [ 3drop 0 ] if , set-at
        ] times
    ] { } make ;

: part1 ( -- ) { 0 3 1 6 7 5 } 2020 play-game last . ;
: part2 ( -- ) { 0 3 1 6 7 5 } 30000000 play-game last . ;  ! 19s

New Annotation

Summary:
Author:
Mode:
Body: