Rule 30

For other topics related to the FreeBASIC project or its community.
Provoni
Posts: 391
Joined: Jan 05, 2014 12:33
Location: Belgium

Rule 30

Postby Provoni » Jul 11, 2020 9:16

This program generates Stephen Wolfram's rule 30. It seems that the general conjecture is that the center column may act as a stream of random bits.

Stephen offers $30,000 in prizes for people who can answer problems related to rule 30: https://www.rule30prize.org/

Code: Select all

'Stephen Wolfram rule 30 with $30,000 in prizes: https://writings.stephenwolfram.com/2019/10/announcing-the-rule-30-prizes/

'- Problem 1: Does the center column always remain non-periodic?
'- Problem 2: Does each color of cell occur on average equally often in the center column?
'- Problem 3: Does computing the n'th cell of the center column require at least O(n) computational effort?

dim as ulongint r,s,i,j,ver=1000 '<------------------------ *** STEPS *** (use even number)
dim as ulongint cen=(ver\2)+1,hor=(ver*2)
redim shared as byte a1(hor+2),a2(hor+2)
static as byte r30(1,1,1)

r30(1,1,1)=0 'Rule 30 matrix
r30(1,1,0)=0
r30(1,0,1)=0
r30(1,0,0)=1
r30(0,1,1)=1
r30(0,1,0)=1
r30(0,0,1)=1
r30(0,0,0)=0

a1(cen)=1 'The first black square

screenres 1000,500,32 'screenres hor,ver,32

for s=1 to ver step 2
   
   for i=0 to hor
      if i=cen then r+=a1(i)
      if a1(i)=1 then pset(i,s-1)
      a2(i+1)=r30(a1(i),a1(i+1),a1(i+2))
   next i
   for i=0 to hor
      if i=cen then r+=a2(i)
      if a2(i)=1 then pset(i,s)
      a1(i+1)=r30(a2(i),a2(i+1),a2(i+2))
   next i
   j+=2
   
next s

draw string(20,20),str(ver)+" steps, mean: "+str(r/j)

sleep
Last edited by Provoni on Jul 11, 2020 10:38, edited 1 time in total.
badidea
Posts: 2152
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Rule 30

Postby badidea » Jul 11, 2020 9:58

Aborting due to runtime error 6 (out of bounds array access) at line 30 of test.bas::()
integer
Posts: 392
Joined: Feb 01, 2007 16:54
Location: usa

Re: Rule 30

Postby integer » Jul 12, 2020 14:53

r30(1,1,1)=0 'Rule 30 matrix
r30(1,1,0)=0 <-- r30(1,1,0) = 1
r30(1,0,1)=0
r30(1,0,0)=1
r30(0,1,1)=1
r30(0,1,0)=1 <-- r30(0,1,0) = 0
r30(0,0,1)=1
r30(0,0,0)=0

using the rule 30 spec my values differ.
Provoni
Posts: 391
Joined: Jan 05, 2014 12:33
Location: Belgium

Re: Rule 30

Postby Provoni » Jul 15, 2020 17:11

@integer, that is another rule number.

Update, arrays should be in bound and added support for colors + some optimization:

Code: Select all

'Stephen Wolfram rule 30 with $30,000 in prizes: https://writings.stephenwolfram.com/2019/10/announcing-the-rule-30-prizes/

'- Problem 1: Does the center column always remain non-periodic?
'- Problem 2: Does each color of cell occur on average equally often in the center column?
'- Problem 3: Does computing the n'th cell of the center column require at least O(n) computational effort?

dim as ulongint r,s,i,j,k,ver=1000 '<------------------------ *** STEPS *** (use even number)
dim as ulongint hor=(ver*2),cen=(hor\2)+1
redim shared as byte a1(hor+1),a2(hor+1)
redim shared as byte c1(hor+1),c2(hor+1)
static as byte rule(1,1,1)
static as byte rcol(1,1,1)

rule(1,1,1)=0:rcol(1,1,1)=1 'Rule 30 matrix
rule(1,1,0)=0:rcol(1,1,0)=2
rule(1,0,1)=0:rcol(1,0,1)=3
rule(1,0,0)=1:rcol(1,0,0)=5
rule(0,1,1)=1:rcol(0,1,1)=6
rule(0,1,0)=1:rcol(0,1,0)=7
rule(0,0,1)=1:rcol(0,0,1)=8
rule(0,0,0)=0:rcol(0,0,0)=4

a1(cen)=1 'The first black square
c1(cen)=8

screenres hor,ver,32

dim as double t=timer

dim as byte drawrule=1

for s=1 to ver step 2
   
   for i=cen-j-2 to cen+j
      if i=cen then r+=a1(i)
      if drawrule=1 then
         select case c1(i)
            'case 1:pset(i,j),rgb(255,255,255)
            'case 2:pset(i,j),rgb(255,255,255)
            'case 3:pset(i,j),rgb(255,255,255)
            'case 4:pset(i,j),rgb(255,255,255)
            case 5:pset(i,j),rgb(255,255,255)
            case 6:pset(i,j),rgb(255,255,255)
            case 7:pset(i,j),rgb(255,255,255)
            case 8:pset(i,j),rgb(255,255,255)
         end select
         c2(i+1)=rcol(a1(i),a1(i+1),a1(i+2))
      end if
      a2(i+1)=rule(a1(i),a1(i+1),a1(i+2))
   next i
   j+=1
   for i=cen-j-2 to cen+j
      if i=cen then r+=a2(i)
      if drawrule=1 then
         select case c2(i)
            'case 1:pset(i,j),rgb(255,255,255)
            'case 2:pset(i,j),rgb(255,255,255)
            'case 3:pset(i,j),rgb(255,255,255)
            'case 4:pset(i,j),rgb(255,255,255)
            case 5:pset(i,j),rgb(255,255,255)
            case 6:pset(i,j),rgb(255,255,255)
            case 7:pset(i,j),rgb(255,255,255)
            case 8:pset(i,j),rgb(255,255,255)
         end select
         c1(i+1)=rcol(a2(i),a2(i+1),a2(i+2))
      end if
      a1(i+1)=rule(a2(i),a2(i+1),a2(i+2))
   next i
   j+=1
   
next s

draw string(20,20),str(j)+" steps in "+str(timer-t)+" seconds, mean: "+str(r/j)

sleep

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 11 guests