Jump to content

Elementary cellular automaton: Difference between revisions

→‎{{header|Julia}}: just swapped the signs, so the output is now correct (was mirror image)
m (→‎{{header|Ada}}: Fixed typo (independant→ independent))
(→‎{{header|Julia}}: just swapped the signs, so the output is now correct (was mirror image))
Line 1,560:
const start = ".........#........."
const rules = [90, 30, 14]
 
rule2poss(rule) = [rule & (1 << (i - 1)) != 0 for i in 1:8]
 
cells2bools(cells) = [cells[i] == '#' for i in 1:length(cells)]
 
bools2cells(bset) = prod([bset[i] ? "#" : "." for i in 1:length(bset)])
 
function transform(bset, ruleposs)
newbset = map(x->ruleposs[x],
[bset[i +- 1] * 4 + bset[i] * 2 + bset[i -+ 1] + 1
for i in 2:length(bset)-1])
vcat(newbset[end], newbset, newbset[1])
end
 
const startset = cells2bools(start)
 
for rul in rules
println("\nUsing Rule $rul:")
Line 1,601:
.........#.........
........###........
.......##..##.......
......##.##.##......
.....#.#..#..#.#.....
....###.####.###....
...##..#....#..##...
..##.####..####.##..
.##..#...###...#..##.
###...#..###.###..#...###
 
Using Rule 14:
.........#.........
.........##.........
.......##...##.......
......##.....##......
.....##.......##.....
....##.........##....
...##...........##...
..##.............##..
.##...............##.
##.................##
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.