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: . 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 .