Algae Growth
rem Program Name: Algae Growth Model
rem Author: OBese87
rem Date: 20/1/10
rem ==================
rem Rules
rem 1. A -> AB
rem 2. B -> A
rem ==================
rem set generations to run
maxgen = 10
rem Start with one A
algae$ = "A"
rem === MAIN ===
for i = 1 to maxgen
algae$ = algae_growth(algae$)
print i;". ";algae$
next i
wait key
end
rem === FUNCTIONS ===
function algae_growth(main$)
feedback$=""
for x = 1 to len(main$)
select mid$(main$,x)
case "A" : feedback$ = feedback$+"AB" : endcase
case "B" : feedback$ = feedback$+"A" : endcase
endselect
next x
endfunction feedback$
condensed to 20 lines
rem set generations to run
maxgen = 10
rem Start with one A
algae$ = "A"
rem === MAIN ===
for i = 1 to maxgen
algae$ = algae_growth(algae$)
print i;". ";algae$
next i
wait key:end
rem === FUNCTIONS ===
function algae_growth(main$)
feedback$=""
for x = 1 to len(main$)
select mid$(main$,x)
case "A" : feedback$ = feedback$+"AB" : endcase
case "B" : feedback$ = feedback$+"A" : endcase
endselect
next x
endfunction feedback$
Fibonacci Sequence (using string manipulation)
rem Program Name: Fibonacci Sequence
rem Author: OBese87
rem Date: 20/1/10
rem ==================
rem Rules
rem 1. A -> B
rem 2. B -> AB
rem ==================
rem set generations to run
maxgen = 20
rem Start with one A
fib$ = "A"
rem message
print "This program prints the famous Fibonacci Sequence."
rem === MAIN ===
for i = 0 to maxgen
print len(fib$)
fib$ = fibonacci$(fib$)
next i
wait key
end
rem === FUNCTIONS ===
function fibonacci$(main$)
feedback$=""
for x = 1 to len(main$)
select mid$(main$,x)
case "A" : feedback$ = feedback$+"B" : endcase
case "B" : feedback$ = feedback$+"AB" : endcase
endselect
next x
endfunction feedback$
condensed
maxgen = 20 : rem set generations to run
fib$ = "A" : rem initialise string
rem message
print "This program prints the famous Fibonacci Sequence."
rem === MAIN ===
for i = 0 to maxgen
print len(fib$)
fib$ = fibonacci$(fib$)
next i
wait key:end
rem === FUNCTIONS ===
function fibonacci$(main$)
feedback$=""
for x = 1 to len(main$)
select mid$(main$,x)
case "A" : feedback$ = feedback$+"B" : endcase
case "B" : feedback$ = feedback$+"AB" : endcase
endselect
next x
endfunction feedback$
Fibonacci Sequence (using a recursive function)
rem Program Name: Fibonacci Sequence (recursive)
rem Author: OBese87
rem Date: 20/1/10
rem ==================
rem set generations to run
maxgen = 26
rem message
print "This program prints the famous Fibonacci Sequence."
rem === MAIN ===
fibonacci(0,1,maxgen)
wait key
end
rem === FUNCTIONS ===
function fibonacci(old,new,g)
print new
if g > 0 then fibonacci(new,old+new,g-1)
endfunction
"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright