Paste: aoc 2018 day 8 part 1

Author: Krenium
Mode: factor
Date: Sat, 8 Dec 2018 07:16:31
Plain Text |
: input ( -- seq )
    "input8.txt" ascii file-lines first " " split
    [ parse-number ] map ;

: next-leaf ( seq -- seq' leaf )
    [
        <evens> [ 0 = ] find drop 2 * dup
        [ 2 - swap ] [ 2 + ] [ 1 + ] tri
    ]
    [ nth + ]
    [ 3dup subseq [ snip append ] dip ]
    tri
    [ [ [ 1 - ] change-nth ] keep ] dip ;

: get-nodes ( nums -- seq )
    [
        [
            [
                [ next-leaf , ] [ drop , return ] recover
            ] forever
        ] with-return
    ] { } make nip ;

: part1 ( -- ) input get-nodes [ 2 tail sum ] map-sum . ;

New Annotation

Summary:
Author:
Mode:
Body: