Showing posts with label Self-organisation. Show all posts
Showing posts with label Self-organisation. Show all posts

Spider webs by natural selection

I recently discovered this awesome BBC BASIC program for simulating spider webs through natural selection. It was written by Matthew Tizard for the BBC Acorn User magazine October 1992.

Natural selection left running on a BBC Master 128 for a couple of days.

The program generates nine 'spider webs'. The fittest spider web is the web that catches the most 'flies'.  This web is then chosen to go into the next generation.

Natural selection running on BeebEm with 6502 Second processor showing nine generations with 'flies' turned off.


I found that the program is best run with your second processor turned on (for hopefully obvious reasons). In fact I found that you get approximately three times improvement in speed, with one generation taking about twenty seconds to generate, draw and test on screen.

You can easily switch on your second processor using BeebEm as shown above.

Another version of the program allows you to control evolution by choosing which web you wish to survive into the next generation. In this way you can select for characteristics that you like, not necessarily the ones that will catch the most flies.

Assuming that the program is in the public domain I have put the files onto a BBC disk image which you can download from the link below.
BBC Disk Image

You will need to load the disk image into your emulator program, or directly into your microcomputer using the datacenter, MMC unit or otherwise copy it onto a floppy disk.

There is a readme file which can be loaded with *type T.readme

The programs can be executed with CHAIN "ArtAuto" OR CHAIN "ArtLife".  Press <ESCAPE> and type LIST to see the program code.


+1 Geek Experience point for Matthew Tizard

#geek #bbcmicro #naturalselection #spiderwebs

Assembly language hacked by 14-year-olds

The following two programs are very impressive examples of independent work produced by two 14-year-old boys using my Little Man Computer simulator.

The first one by Eric is an integer division program that can deal with both negative and positive integers and which returns both the whole number division and the remainder.  The second program, written by Will, is a general purpose calculator that can deal with addition, subtraction, multiplication, integer division, square roots and raising one number to power.

Not bad stuff for a program that can only ADD and SUBTRACT(!)

Eric's division program first.  Enter two numbers X and Y respectively and the program calculates X DIV Y and X MOD Y.


#DIVISION with remainders and negatives!

#By Eric
.
INP
STA TOP #Input the top part of the fraction, e.g. [8]/3
BRZ TOPZERO #If top zero simulate input and then
#output 0
INP
BRZ HALT #If zero, just go. DIVBYZERO
STA BOTTOM #Input the bottom part of the
#fraction, e.g. 8/[3]
BRA NCHKO
.
TOPZERO INP #sim input
LDA SWAP #load swap (0 by now)
OUT #outputs it
HLT #and stops!
.
NCHKO BRP NCHKT #check bottom for efficiency
SUB BOTTOM #use clever maths to realize that x-(x-x) = -x
SUB BOTTOM #if the numbers weren't positive it would
STA BOTTOM #mess the program up
LDA MINUSONE #negmult is now -1, so it's negative
STA NEGMULT
BRA NCHKT
.
NCHKT LDA TOP #check top now
BRP START #if not negative just go to setup
SUB TOP #same clever maths as before
SUB TOP
STA TOP
LDA NEGMULT #loads the negative multiplier
SUB NEGMULT
SUB NEGMULT
STA NEGMULT
#and uses SAME clever maths trick to invert, again
LDA TOP
BRA START
.
.
.
START SUB BOTTOM
#alright so I better explain
#the thing is that the way I divide is:
#I count how many times I subtract the bottom from the top
#When the top is negative it checks for a remainder
#by adding the bottom on again
#that is the remainder
#so example:
#14/3 - it subtracts 3 from 14 5 times
#and then adds 3 again, takes one away from the
#5 times (makes it 4) and the remainder is the result after
#adding 3. 4r2 which is the correct answer.
BRP NFINISH #if positive NotFINISHed
BRA FINISHUP#else finish all things up
NFINISH STA SWAP #stores current result in swap
LDA RESULT #loads the result
ADD ONE #increments
STA RESULT #stores result
LDA SWAP
BRA START #loads swap and removes and starts again
.
.
.
FINISHUP ADD BOTTOM #adds bottom to figure out remainder
STA REMAINDER #stores that as remainder
LDA NEGMULT #remember this?
BRP OUTPUT #if negmult is normal just output
LDA RESULT
SUB RESULT #else use my favourite maths trick
SUB RESULT
STA RESULT
OUTPUT LDA RESULT #easy peasy
OUT #output result
LDA REMAINDER
OUT #remainder
HALT HLT #cya 

#Variables
NEGMULT DAT 1 #Negative multiplier
MINUSONE DAT -1 #-1 [CONST]
ONE DAT 1 #1 [CONST]
TOP DAT 0 #The top part of fraction
BOTTOM DAT 0 #Botttom part
RESULT DAT 0 #Result
REMAI DAT 0 #Remainder
SWAP DAT 0

#Swap data used by program for general stuff




Here is Will's general purpose calculator.  The first number input is the menu option:
0: for square root
2: for division
3: for subtraction
4: for addition
5: for powers
6: for multiplication


#Will
#A general purpose calculator which works with the limitations of the little man computer
#
INP # Press zero for square root, two for divide, three for subtract, four for addition and five for power, six for multiply
STA D
INP #Enter the first number, this is the number that all the functions will be done to
STA A
INP #With square and power, due to limitations of little man computer size, does nothing but is the operating number
STA B
LDA D
BRZ SQUARE #Go to square function
SUB ONE
BRZ DIVIDE #Go to multiply function
SUB ONE
BRZ SUBTRACT #Go to subract function
SUB TWO
BRZ ADDITION #Go to addition function
SUB ONE
BRZ POWER #Go to Power

LDA B #Multiply Function
SUB ONE
STA B
LOOP LDA C
ADD A
STA C
LDA B
SUB ONE
STA B
BRP LOOP
LDA C
OUT
HLT

DIVIDE LDA A #Divide function
STA A
LOOPD LDA COUNT
ADD ONE
STA COUNT
LDA A
SUB B
STA A
BRZ ZERO
BRP LOOPD
ZERO LDA COUNT
OUT
HLT


ADDITION LDA A #Addition Function
ADD B
OUT
HLT

SUBTRACT LDA A #Subtract Function
SUB B
OUT
HLT



SQUARE LDA A #Square root function
STA A
LOOPS LDA COUNT
ADD ONE
STA COUNT
LDA A
SUB X
STA A
LDA X
ADD TWO
STA X
LDA A
BRP LOOPS
LDA COUNT
SUB ONE
OUT
HLT

POWER LDA A #Power function
STA COUNT
LDA COUNT
SUB ONE
STA COUNT
LOOPP LDA COUNT
SUB ONE
STA COUNT
LDA RESULT
ADD A
STA RESULT
LDA COUNT
BRP LOOPP
LDA RESULT
OUT
HLT


A DAT
B DAT
C DAT 000
COUNT DAT
X DAT 001
ONE DAT 001
TWO DAT 002
RESULT DAT


Circles

Circles is a program to aid independent learning in mathematics.


Circles was written for Mr Bakr Al Bazi, Mathematics teacher at the Grammar School at Leeds, who writes:


"3 circles, 6 values for each circle. Students started to investigate these values with no input from me."

"Independent Learning was taking place. Ratio, radius, diameter.... every notion that involved circles was discussed and then pi came in." 

"It was wonderful! I realised that adopting the use of new technology to support traditional instructions has not only it made me change the way I teach, but also the way students learn." 

Label

World Karma Game