Rhombic wrote:Just to practice, I've decided to attempt the Fibonacci (binary) sequence creation in CGoL, as someone requested in the Script request thread.
I have obtained the binary numbers fairly easily, but even after reading how the cell lists work for Golly, I am still unsure about how to plot the cells or create the cell list from the numbers...
You're definitely most of the way there. Just by the way, in Python (or Lua) you can dodge the extra variable start2prime
Code: Select all
previousfib, fib, fiblist = 1, 1, 
for i in range(100):
previousfib, fib = fib, previousfib+fib
All the assignments happen at the same time, so you don't have to use an extra variable to store transitional values. But it works just as well the way you're doing it, and maybe it's less confusing.
Each of your binnums has some number of "1" digits in it, so if you wanted to build a cell list, you'd have to iterate through binnum[-1] (the last string in the binnum list) and add an appropriate (x,y) value to your cell list every time you see a "1".
build a multistate cell list, and then have one cell per binary digit, with a state of either 0 or 1.
But then you'd have to deal with the weird detail that multistate cell lists always have to be odd-length. In this case there's probably not much point, unless you want to do a "copy"-mode paste and blank out the empty cells.
-- Anyway, it might be simpler to directly setcell() the cells you want to turn ON, one at a time, and skip the cell list entirely. There are lots of other ways to do it, but here's what I ended up with, with orientation matching the sample output in the original request:
Code: Select all
import golly as g
totalnumbers = int(g.getstring("How many Fibonacci numbers:","1000"))
decnum = [1,1]
while len(decnum)<totalnumbers: # build the list of Fibonacci numbers
for j in range(totalnumbers):
reversedbin=bin(decnum[j])[::-1] # [::-1] = slice starts at 0, ends at 0, count by -1
for k in range(len(reversedbin)-2): # the -2 ignores the "b0", now at the end
Of course, the original request asked for a Lua script. [I keep hoping that enough detail will eventually get posted so that someone can figure out what's going wrong with gameoflifemaniac's Python install, but no luck so far...!]
This script would be a little more work in Lua, mainly because I think you'd have to write your own bin() function. And Lua doesn't support arbitrarily long integers, so you might be stuck with Fibonacci numbers only up to 2^32 or 2^53 or 2^64 (depending on how you do it). Fibonacci numbers grow fast, so any of those would be a surprisingly short chunk of fractal.
A nice way around that
would be to store all your Fibonacci numbers as binary strings or tables in the first place -- in which case you'd have to write a fibadd() function instead of a bin() function, but your Lua script could build a much bigger Fibonacci fractal.