Paste: aoc day 12 part 1

Author: Krenium
Mode: factor
Date: Thu, 13 Dec 2018 04:51:23
Plain Text |
CONSTANT: pad 300
SYMBOL: rules

: get-input ( -- pots )
    "input12.txt" ascii file-contents R/ [#\.]+/
    all-matching-subseqs unclip [ 2 group >hashtable rules set ]
    dip [ pad CHAR: . <repetition> dup ] dip glue "" like ;

: new-state ( n pots -- x )
    [ [ 2 - ] [ 3 + ] bi ] dip subseq rules get at ;

: next-gen ( pots -- pots' )
    2 over length 3 - [a,b] [ [ swap new-state % ] with each ]
    "" make [ ".." dup ] dip glue ;

: pot-sum ( pots -- n )
    pad cut [ reverse [ [ CHAR: # = ] dip 0 ? neg ] map-index
    sum ] dip [ [ CHAR: # = ] dip 0 ? ] map-index sum + ;

get-input pot-sum .

New Annotation

Summary:
Author:
Mode:
Body: