Published
Edited
Sep 22, 2020
Insert cell
md`# Celular Automaton

Wrote some code as first experiement in cellular automaton.

First setup basic step iterator that follows Wolfram notation rules to iterate a 1 dimensional cellular automaton.

You could have a token assigned to areas of a 2d arena for a game of life cellular life lottery!
When it is on your tile you get paid.

# Interesting JS Automaton frameworks
https://rileyjshaw.com/terra/#main
https://sanojian.github.io/cellauto/#usage
https://github.com/kgolid/hatch-automata


# Links re: Automaton NFTs :)

https://github.com/ether-automaton/automaton-create
http://anfederico.eth.link/Immortalize-Your-Creations/


`
Insert cell
(16**40)/256/256/256/256/256/256/256/256/256/256/256/256/256/256/256/256/256/256
Insert cell
Insert cell
step("111")
Insert cell
Insert cell
function iterate( start, time, rule=127-30 ) {
var a = []
let last = start
let accounts=[], z=[]
for (let i=0; i<time; i++) {
a.push(last) // add state to array
accounts.push(0)
let payouts = calculatePayouts(last, _bids(time, 100) )
let updatedAccounts = doPayouts( payouts, accounts)
z.push( updatedAccounts.slice() )
last = step(last, rule)
}
let normalized = z.pop().map( (a) => a/time) // map the last element of the array to normalized values
return {a,normalized }
}
Insert cell
iterate( "1" , 100, 110 )//.map( (x)=> x.z x[2]).reduce( (a,b) => a +b)/30
//iterate( Number(1).toString(2).padStart(0,"0") ,30 ).map( (x)=>x[2]).reduce( (a,b) => a +b)/30


//iterate( Number(1).toString(2).padStart(0,"0") ,30 )//.map( (x)=>x[2])//.reduce( (a,b) => a +b)/2520
// iterate( Number(1).toString(2).padStart(1,"0") ,300)
// iterate( Number((2**40)-2**5).toString(2).padStart(1,"0") ,2520)
Insert cell
Insert cell
_bids(100) // returns a sorted array of n 'bids' from 0-1
Insert cell
function calculatePayouts(a,bids=[]) { // receives string "10110" and calculates which accounts should be paid
let payout=[]
for ( let [i, n] of a.split("").entries() ) {
let total=a.split("1").length-1 //split list by 1s and count how many 1s there are
if(n==="1" ) {
let bid = bids[i] ? bids[i] : 1
payout.push({account:i, amount: n/total * bid})
}
}
return payout
}
Insert cell
Insert cell
function doPayouts(transactions, accounts) { // [{ account, amount}] [account]
for (let transaction of transactions) {
accounts[ transaction.account ] += transaction.amount
}
return accounts
}
Insert cell
md`amount to pay out for this combo`
Insert cell
class Cellular {
constructor(size) {
this.state = Array(size).fill(0)
return "lets go" // this.state
}
}
Insert cell
new Cellular(2)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more