NB. NB. J-language routines for computing the sequences A179409 - A179415 in Neil Sloane's NB. Online Encyclopedia of Integer Sequences (See http://oeis.org ). NB. Coded by Antti Karttunen (e-mail: .@gmail.com) Jul 12-15 2010. NB. and placed in Public Domain. (Last edited Jul 26 2010). NB. This should work at least with: NB. J602 (Engine: j602/2008-03-03/16:45, Library 6.02.023.) See www.jsoftware.com NB. NB. More concise version of "life"-function borrowed from Cliff Reiter's site NB. at http://webbox.lafayette.edu/~reiterc/j/vector/vlife_index.html NB. in source: http://webbox.lafayette.edu/~reiterc/j/vector/vlife2.html NB. NB. This is my original version for computing the next generation of a pattern NB. with the rules of Conway's Game of Life, on toroidal array (of any size). NB. As you see, it's much too verbose. mylife=:(3&=)@:([(]+(*(1-2&|)))(+/)@:((i.8)&(((((|."1~((1|.i:1){~3&|))(|.~((1|.i:1){~<.@:%&3))])"2 0)>:)~))) NB. This version essentially same as Cliff Reiter's lifes (in vlife2.ijs), NB. but composed in another order: life=:(4&{((3:=])+.[*4:=])+/)@:([:,/1&|.^:(i:1)@|:"2^:2) NB. Also useful, pad around an array, from Cliff Reiter's vlife2.ijs pad=: (+:@[-@+$@]){.([+$@]){. ] NB. Some initial patterns we need, or just for testing: glider=:8 8 $ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 init48s8=:8 8 $ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 init48sinf=:40 pad init48s8 NB. Simulate the same pattern on infinite board. (for us, +80 in size is already an infinity...) init48s26 =: 9 pad init48s8 NB. Works already with this, of size 26x26 as "infinity". init132=:8 8 $ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 nthgenfrominit48s8=: monad def 'life^:y init48s8' nthgenfrominit48sinf=: monad def 'life^:y init48sinf' nthgenfrominit132=: monad def 'life^:y init132' acells=:(+/)@:(+/) NB. Compute the number of alive cells. NB. Compute the number of columns with at least one alive cell. We use +. (bit-or) NB. instead of + (ordinary addition) for first summing each column's elements NB. thus resulting 1s for non-empty and 0s for empty columns. Then we just NB. sum the resulting vector of values with (+/). acols=:(+/)@:(+./) NB. Shorter than: acols=:(+/)@:(0&<)@:(+/) NB. Compute the number of rows with at least one alive cell (at least one 1 in that row). NB. Just compose acols and matrix-transpose (|:) arows=:acols@:|: NB. Alternatively: arows=:(+/)@:(0&<)@:#. A179409=:acells@:nthgenfrominit48s8"0 A179410=:acols@:nthgenfrominit48s8"0 A179411=:arows@:nthgenfrominit48s8"0 A179412=:acells@:nthgenfrominit132"0 A179413=:acols@:nthgenfrominit132"0 A179414=:arows@:nthgenfrominit132"0 A179415=:acells@:nthgenfrominit48sinf"0 NB. A179412 i.68 NB. 8 8 9 10 12 16 13 23 16 22 18 24 16 20 21 23 28 19 18 18 23 22 18 27 16 20 10 10 10 13 15 19 22 18 25 NB. 18 19 23 23 20 21 22 30 19 22 21 20 28 19 16 14 9 13 12 13 14 16 23 15 19 16 26 16 12 12 9 8 8 NB. NB. A179413 i.68 (also lexicographically the first rotation) NB. 3 4 5 5 6 6 6 7 8 8 8 8 7 8 8 8 8 8 7 7 8 8 8 7 7 6 3 5 5 5 6 8 7 8 8 7 7 7 8 7 8 8 8 7 7 8 8 8 6 6 7 5 6 8 7 7 8 8 8 6 7 7 8 6 6 4 3 4 NB. A179414 i.68 (this as well!) NB. 4 4 4 4 5 6 7 8 8 8 7 8 7 7 7 8 8 8 7 7 7 7 6 8 8 8 7 4 6 6 6 7 7 8 8 7 8 7 8 8 8 8 8 8 8 7 8 8 6 7 7 5 4 5 5 5 6 6 7 7 8 8 7 5 5 5 4 4 NB. (+/ % #) A179409 i.24 = 16.9167 NB. (+/ % #) A179410 i.24 = 5.5 NB. (+/ % #) A179411 i.24 = 6.41667 NB. (+/ % #) A179412 i.66 = 17.7273 NB. (+/ % #) A179413 i.66 = 6.84848 NB. (+/ % #) A179414 i.66 = 6.72727 NB. Code to output the sequences: require 'files' digvec2str=:a.{~(48&+) nthdigit=:10|<.@:(%(10&^)) width10=:((>:@:<.@:(10&^.))`1:)@.(0&=) num2digvec=:(nthdigit(i.@:-@width10)) num2str=:digvec2str@:num2digvec"0 num2strwithcomma=:(','&,)@:digvec2str@:num2digvec"0 vec2csvstr=:,@:num2strwithcomma"1 NB. Use as: '/home/karttu/seqs/A179409.txt' writeseqsimple A179409 i.96 writeseqsimple=:((vec2csvstr@:])fwrite(<@:[)) '/home/karttu/seqs/A179409.txt' writeseqsimple A179409 i.72 '/home/karttu/seqs/A179410.txt' writeseqsimple A179410 i.120 '/home/karttu/seqs/A179411.txt' writeseqsimple A179411 i.120 '/home/karttu/seqs/A179412.txt' writeseqsimple A179412 i.72 '/home/karttu/seqs/A179413.txt' writeseqsimple A179413 i.99 '/home/karttu/seqs/A179414.txt' writeseqsimple A179414 i.99 '/home/karttu/seqs/A179415.txt' writeseqsimple A179415 i.96