Paste: aoc17

Author: jon
Mode: factor
Date: Fri, 8 Jan 2021 17:15:27
Plain Text |
: neighbours ( pos -- neighbours )
3 -1 1 [a,b] <array> <product-sequence> [ [ zero? ] all? ] reject
[ v+ ] with map ; 
: step ( new pos old -- )
dupd 
[ [ neighbours ] dip [ in? ] curry count ]
[ in? ] 2bi
[ 2 3 between? [ 2drop ] [ swap delete ] if ]
[ 3 = [ swap adjoin ] [ 2drop ] if ] if ;

"/home/harperjon/Téléchargements/input17" ascii file-lines
HS{ } clone [ [
  [ [ rot ] dip swap CHAR: # = [ [ 0 3array ] dip adjoin ] [ 3drop ] if ] curry curry each-index
] curry each-index ] keep
6 [ dup members length . dup members dup [ neighbours ] map concat append
members over [ clone [ step ] curry with each ] keep ] times
members length .



: neighbours2 ( pos -- neighbours )
4 -1 1 [a,b] <array> <product-sequence> [ [ zero? ] all? ] reject
[ v+ ] with map ; 
: step2 ( new pos old -- )
dupd 
[ [ neighbours2 ] dip [ in? ] curry count ]
[ in? ] 2bi
[ 2 3 between? [ 2drop ] [ swap delete ] if ]
[ 3 = [ swap adjoin ] [ 2drop ] if ] if ;

"/home/harperjon/Téléchargements/input17" ascii file-lines
HS{ } clone [ [
  [ [ rot ] dip swap CHAR: # = [ [ 0 0 4array ] dip adjoin ] [ 3drop ] if ] curry curry each-index
] curry each-index ] keep
6 [ dup members length . dup members dup [ neighbours2 ] map concat append
members over [ clone [ step2 ] curry with each ] keep ] times
members length .

New Annotation

Summary:
Author:
Mode:
Body: