X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=blobdiff_plain;f=extra%2Frosetta-code%2Fone-d-cellular%2Fone-d-cellular.factor;h=8476073daa5d56407e1e16a3ed12c2946adcb85c;hp=56567f4ba23d9a15f3206fb1f590ff6d7a2e9a61;hb=6d4293b5822d769619f66e46e64b704ddfe41b43;hpb=b7bb69b178712e9d135362ebd6efa69c9b8371ba diff --git a/extra/rosetta-code/one-d-cellular/one-d-cellular.factor b/extra/rosetta-code/one-d-cellular/one-d-cellular.factor index 56567f4ba2..8476073daa 100644 --- a/extra/rosetta-code/one-d-cellular/one-d-cellular.factor +++ b/extra/rosetta-code/one-d-cellular/one-d-cellular.factor @@ -11,35 +11,35 @@ IN: rosetta-code.one-d-cellular ! Cells in the next generation of the array are calculated based ! on the value of the cell and its left and right nearest -! neighbours in the current generation. If, in the following +! neighbors in the current generation. If, in the following ! table, a live cell is represented by 1 and a dead cell by 0 then ! to generate the value of the cell at a particular index in the ! array of cellular values you use the following table: ! 000 -> 0 # ! 001 -> 0 # -! 010 -> 0 # Dies without enough neighbours -! 011 -> 1 # Needs one neighbour to survive +! 010 -> 0 # Dies without enough neighbors +! 011 -> 1 # Needs one neighbor to survive ! 100 -> 0 # -! 101 -> 1 # Two neighbours giving birth -! 110 -> 1 # Needs one neighbour to survive +! 101 -> 1 # Two neighbors giving birth +! 110 -> 1 # Needs one neighbor to survive ! 111 -> 0 # Starved to death. : bool-sum ( bool1 bool2 -- sum ) [ [ 2 ] [ 1 ] if ] [ [ 1 ] [ 0 ] if ] if ; -:: neighbours ( index world -- # ) +:: neighbors ( index world -- # ) index [ 1 - ] [ 1 + ] bi [ world ?nth ] bi@ bool-sum ; -: count-neighbours ( world -- neighbours ) - [ length ] keep [ neighbours ] curry map ; +: count-neighbors ( world -- neighbours ) + [ length ] keep [ neighbors ] curry map ; -: life-law ( alive? neighbours -- alive? ) +: life-law ( alive? neighbors -- alive? ) swap [ 1 = ] [ 2 = ] if ; : step ( world -- world' ) - dup count-neighbours [ life-law ] ?{ } 2map-as ; + dup count-neighbors [ life-law ] ?{ } 2map-as ; : print-cellular ( world -- ) [ CHAR: # CHAR: _ ? ] "" map-as print ;