Infinite length
1
func evolve(rule, bin) {
2
var offset = 0
3
var (l='', r='')
4
Inf.times {
5
bin.sub!(/^((.)\g2*)/, {|_s1, s2| l = s2; offset -= s2.len; s2*2 })
6
bin.sub!(/(.)\g1*$/, {|s1| r = s1; s1*2 })
7
printf("%5d| %s%s\n", offset, ' ' * (40 + offset), bin.tr('01','.#'))
8
bin = [l*3, 0.to(bin.len-3).map{|i| bin.substr(i, 3) }..., r*3 ].map { |t|
9
1 & (rule >> t.bin)
10
}.join
11
}
12
}
13
14
evolve(90, "010")
Copied!

Output:

1
-1| ..#..
2
-2| ..#.#..
3
-3| ..#...#..
4
-4| ..#.#.#.#..
5
-5| ..#.......#..
6
-6| ..#.#.....#.#..
7
-7| ..#...#...#...#..
8
-8| ..#.#.#.#.#.#.#.#..
9
-9| ..#...............#..
10
-10| ..#.#.............#.#..
11
-11| ..#...#...........#...#..
12
-12| ..#.#.#.#.........#.#.#.#..
13
-13| ..#.......#.......#.......#..
14
-14| ..#.#.....#.#.....#.#.....#.#..
15
-15| ..#...#...#...#...#...#...#...#..
16
-16| ..#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#..
17
-17| ..#...............................#..
18
-18| ..#.#.............................#.#..
19
-19| ..#...#...........................#...#..
20
-20| ..#.#.#.#.........................#.#.#.#..
21
Copied!
Last modified 1yr ago
Copy link
Contents
Output: