Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,5 +1,5 @@
|
|||
V gen = ‘_###_##_#_#_#_#__#__’.map(ch -> Int(ch == ‘#’))
|
||||
L(n) 10
|
||||
L 10
|
||||
print(gen.map(cell -> (I cell != 0 {‘#’} E ‘_’)).join(‘’))
|
||||
gen = [0] [+] gen [+] [0]
|
||||
gen = (0 .< gen.len - 2).map(m -> Int(sum(:gen[m .+ 3]) == 2))
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Cellular_Automata is
|
||||
type Petri_Dish is array (Positive range <>) of Boolean;
|
||||
|
||||
procedure Step (Culture : in out Petri_Dish) is
|
||||
Left : Boolean := False;
|
||||
This : Boolean;
|
||||
Right : Boolean;
|
||||
begin
|
||||
for Index in Culture'First..Culture'Last - 1 loop
|
||||
Right := Culture (Index + 1);
|
||||
This := Culture (Index);
|
||||
Culture (Index) := (This and (Left xor Right)) or (not This and Left and Right);
|
||||
Left := This;
|
||||
end loop;
|
||||
Culture (Culture'Last) := Culture (Culture'Last) and not Left;
|
||||
end Step;
|
||||
|
||||
procedure Put (Culture : Petri_Dish) is
|
||||
begin
|
||||
for Index in Culture'Range loop
|
||||
if Culture (Index) then
|
||||
Put ('#');
|
||||
else
|
||||
Put ('_');
|
||||
end if;
|
||||
end loop;
|
||||
end Put;
|
||||
|
||||
Culture : Petri_Dish :=
|
||||
( False, True, True, True, False, True, True, False, True, False, True,
|
||||
False, True, False, True, False, False, True, False, False
|
||||
);
|
||||
begin
|
||||
for Generation in 0..9 loop
|
||||
Put ("Generation" & Integer'Image (Generation) & ' ');
|
||||
Put (Culture);
|
||||
New_Line;
|
||||
Step (Culture);
|
||||
end loop;
|
||||
end Cellular_Automata;
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
evolve: function [arr][
|
||||
ary: [0] ++ arr ++ [0]
|
||||
ret: new []
|
||||
ret: []
|
||||
loop 1..(size ary)-2 'i [
|
||||
a: ary\[i-1]
|
||||
b: ary\[i]
|
||||
c: ary\[i+1]
|
||||
|
||||
if? 2 = a+b+c -> 'ret ++ 1
|
||||
else -> 'ret ++ 0
|
||||
switch 2 = a+b+c -> 'ret ++ 1
|
||||
-> 'ret ++ 0
|
||||
]
|
||||
ret
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,108 +0,0 @@
|
|||
Identification division.
|
||||
Program-id. rc-1d-cell.
|
||||
|
||||
Data division.
|
||||
Working-storage section.
|
||||
|
||||
*> "Constants."
|
||||
01 max-gens pic 999 value 9.
|
||||
01 state-width pic 99 value 20.
|
||||
01 state-table-init pic x(20) value ".@@@.@@.@.@.@.@..@..".
|
||||
01 alive pic x value "@".
|
||||
01 dead pic x value ".".
|
||||
|
||||
*> The current state.
|
||||
01 state-gen pic 999 value 0.
|
||||
01 state-row.
|
||||
05 state-row-gen pic zz9.
|
||||
05 filler pic xx value ": ".
|
||||
05 state-table.
|
||||
10 state-cells pic x occurs 20 times.
|
||||
|
||||
*> The new state.
|
||||
01 new-state-table.
|
||||
05 new-state-cells pic x occurs 20 times.
|
||||
|
||||
*> Pointer into cell table during generational production.
|
||||
01 cell-index pic 99.
|
||||
88 at-beginning value 1.
|
||||
88 is-inside values 2 thru 19.
|
||||
88 at-end value 20.
|
||||
|
||||
*> The cell's neighborhood.
|
||||
01 neighbor-count-def.
|
||||
03 neighbor-count pic 9.
|
||||
88 is-comfy value 1.
|
||||
88 is-ripe value 2.
|
||||
|
||||
Procedure division.
|
||||
Perform Init-state-table.
|
||||
Perform max-gens times
|
||||
perform Display-row
|
||||
perform Next-state
|
||||
end-perform.
|
||||
Perform Display-row.
|
||||
Stop run.
|
||||
|
||||
Display-row.
|
||||
Move state-gen to state-row-gen.
|
||||
Display state-row.
|
||||
|
||||
*> Determine who lives and who dies.
|
||||
Next-state.
|
||||
Add 1 to state-gen.
|
||||
Move state-table to new-state-table.
|
||||
|
||||
Perform with test after
|
||||
varying cell-index from 1 by 1
|
||||
until at-end
|
||||
perform Count-neighbors
|
||||
perform Die-off
|
||||
perform New-births
|
||||
end-perform
|
||||
|
||||
move new-state-table to state-table.
|
||||
|
||||
*> Living cell with wrong number of neighbors...
|
||||
Die-off.
|
||||
if state-cells(cell-index) =
|
||||
alive and not is-comfy
|
||||
then move dead to new-state-cells(cell-index)
|
||||
end-if
|
||||
.
|
||||
|
||||
*> Empty cell with exactly two neighbors are...
|
||||
New-births.
|
||||
if state-cells(cell-index) = dead and is-ripe
|
||||
then move alive to new-state-cells(cell-index)
|
||||
end-if
|
||||
.
|
||||
*> How many living neighbors does a cell have?
|
||||
Count-neighbors.
|
||||
Move 0 to neighbor-count
|
||||
if at-beginning or at-end then
|
||||
add 1 to neighbor-count
|
||||
else
|
||||
if is-inside and state-cells(cell-index - 1) = alive
|
||||
then
|
||||
add 1 to neighbor-count
|
||||
end-if
|
||||
if is-inside and state-cells(cell-index + 1) = alive
|
||||
then
|
||||
add 1 to neighbor-count
|
||||
end-if
|
||||
end-if
|
||||
.
|
||||
|
||||
*> String is easier to enter, but table is easier to work with,
|
||||
*> so move each character of the initialization string to the
|
||||
*> state table.
|
||||
|
||||
Init-state-table.
|
||||
Perform with test after
|
||||
varying cell-index from 1 by 1
|
||||
until at-end
|
||||
move state-table-init(cell-index:1)
|
||||
to state-cells(cell-index)
|
||||
end-perform
|
||||
.
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
# We could cheat and count the bits, but let's keep this general.
|
||||
# . = dead, # = alive, middle cells survives iff one of the configurations
|
||||
# below is satisified.
|
||||
survival_scenarios = [
|
||||
'.##' # happy neighbors
|
||||
'#.#' # birth
|
||||
'##.' # happy neighbors
|
||||
]
|
||||
|
||||
b2c = (b) -> if b then '#' else '.'
|
||||
|
||||
cell_next_gen = (left_alive, me_alive, right_alive) ->
|
||||
fingerprint = b2c(left_alive) + b2c(me_alive) + b2c(right_alive)
|
||||
fingerprint in survival_scenarios
|
||||
|
||||
cells_for_next_gen = (cells) ->
|
||||
# This function assumes a finite array, i.e. cells can't be born outside
|
||||
# the original array.
|
||||
(cell_next_gen(cells[i-1], cells[i], cells[i+1]) for i in [0...cells.length])
|
||||
|
||||
display = (cells) ->
|
||||
(b2c(is_alive) for is_alive in cells).join ''
|
||||
|
||||
simulate = (cells) ->
|
||||
while true
|
||||
console.log display cells
|
||||
new_cells = cells_for_next_gen cells
|
||||
break if display(cells) == display(new_cells)
|
||||
cells = new_cells
|
||||
console.log "equilibrium achieved"
|
||||
|
||||
simulate (c == '#' for c in ".###.##.#.#.#.#..#..")
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
include machine.e
|
||||
|
||||
function rules(integer tri)
|
||||
return tri = 3 or tri = 5 or tri = 6
|
||||
end function
|
||||
|
||||
function next_gen(atom gen)
|
||||
atom new, bit
|
||||
new = rules(and_bits(gen,3)*2) -- work with the first bit separately
|
||||
bit = 2
|
||||
while gen > 0 do
|
||||
new += bit*rules(and_bits(gen,7))
|
||||
gen = floor(gen/2) -- shift right
|
||||
bit *= 2 -- shift left
|
||||
end while
|
||||
return new
|
||||
end function
|
||||
|
||||
constant char_clear = '_', char_filled = '#'
|
||||
|
||||
procedure print_gen(atom gen)
|
||||
puts(1, int_to_bits(gen,32) * (char_filled - char_clear) + char_clear)
|
||||
puts(1,'\n')
|
||||
end procedure
|
||||
|
||||
function s_to_gen(sequence s)
|
||||
s -= char_clear
|
||||
return bits_to_int(s)
|
||||
end function
|
||||
|
||||
atom gen, prev
|
||||
integer n
|
||||
|
||||
n = 0
|
||||
prev = 0
|
||||
gen = bits_to_int(rand(repeat(2,32))-1)
|
||||
while gen != prev do
|
||||
printf(1,"Generation %d: ",n)
|
||||
print_gen(gen)
|
||||
prev = gen
|
||||
gen = next_gen(gen)
|
||||
n += 1
|
||||
end while
|
||||
|
||||
printf(1,"Generation %d: ",n)
|
||||
print_gen(gen)
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
(function next cells
|
||||
(... str
|
||||
(map (comp str (count ["#"]) (= 2) #(% "#" "_"))
|
||||
(str "_" cells)
|
||||
"_{cells}"
|
||||
cells
|
||||
(str (skip 1 cells) "_"))))
|
||||
"{skip 1 cells}_")))
|
||||
|
||||
(function generate n cells
|
||||
(join "\n" (reductions next cells (range n))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue