Shop OBEX P1 Docs P2 Docs Learn Events
PROPBrainFsck; an Interpreter for Obfuscated Programming. Code included. — Parallax Forums

PROPBrainFsck; an Interpreter for Obfuscated Programming. Code included.

UltraLazerUltraLazer Posts: 30
edited 2011-03-18 17:44 in Propeller 1
The BrainFsck "programming language is an esoteric programming language noted for its extreme minimalism. It is a Turing tarpit, designed to challenge and amuse programmers, and is not suitable for practical use" - Wikipedia.

there are 8 instructions and they go like:

> increment the data pointer (to point to the next cell to the right).
< decrement the data pointer (to point to the next cell to the left).
+ increment (increase by one) the byte at the data pointer.
- decrement (decrease by one) the byte at the data pointer.
. output a character, the ASCII value of which being the byte at the data pointer.
, accept one byte of input, storing its value in the byte at the data pointer.
[ if the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command*.
] if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command*.

PROPBrainFsck.spin is a quick BrainFsck interpreter that should be able to run most BF code.

I thought BF might be an interesting way to experiment with genetic computation in spin. BF programs generated by the propeller from blocks of BF code could be evaluated (output/memory), recombined, and evolved over time. I wonder how long it would take to evolve 1+1=2? Sounds like a big can of worms...

Anyway, please let me know about any bugs etc.

Lots of great code, and blocks for standard math and logic operations are found on the internet.

PropBrainFsck.spin requires the Parallax Serial Terminal.

Includes 2 BF demo programs.
program1 - Outputs some text
program2 - Outputs arbitrarily many Fibonacci numbers.
(program2 work of Daniel B Cristofani http://www.hevanet.com/cristofd/)

A.

Comments

  • jazzedjazzed Posts: 11,803
    edited 2011-03-17 20:36
    PASM version here :-) Runs hello, 99bottles, primes. Could be optimized more to run faster.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-03-17 21:20
    UltraLazer wrote:
    I thought BF might be an interesting way to experiment with genetic computation in spin.
    Bingo! I've often thought the same thing! The nice thing about BF in this arena is that small structural changes result in much smaller behavioral changes than in other languages. As a consequence, mutation of genes and recombination through crossover is much less likely to throw the entire phenotype under the bus, allowing evolution to have a chance of succeeding.

    -Phil
  • HumanoidoHumanoido Posts: 5,770
    edited 2011-03-18 02:34
    When I run this on a Parallax demo board with an activated PST, only a blank screen appears. Can you provide some instructions to run the demo programs?
  • UltraLazerUltraLazer Posts: 30
    edited 2011-03-18 09:16
    Thanks @jazzed. I guess this is the kind of confusion one can anticipate with a language who's name must be bowdlerized. Oh well, mostly for learning.
    @phil, Exactly, because the genotype and phenotype are so far removed from one another there is good chance that many genes will have no impact on the final computation result. There is allot to be said for the potential to do nothing, that way when the genes need to do something different there is more genetic potential stock piled in tag-along genes that had been useless. It would be cool to run a few populations in parallel on islands in different cogs. As these populations diverge from one another a few genes are allowed to emigrate to another island

    As for the recombination, I was thinking of treating the BF programs like trees. [ ] loops correspond to sexed branch structures (preserve loop "balance"?) and the code/blocks are leaves.

    @humanoid
    I had the interpreter starting and stopping the terminal if you remover "'PST.Stop " on line # 68 it should be good to go. sorry.
  • HumanoidoHumanoido Posts: 5,770
    edited 2011-03-18 10:58
    UltraLazer wrote: »
    It would be cool to run a few populations in parallel on islands in different cogs. As these populations diverge from one another a few genes are allowed to emigrate to another island
    UltraLazer, I'm very interested in seeing code do that. When it's running from cogs in one chip, it could be transferred to cogs across many chips in a different program version! Can you write a simple demo for the cogs in one chip?
  • HumanoidoHumanoido Posts: 5,770
    edited 2011-03-18 11:04
    UltraLazer wrote: »
    @humanoid: I had the interpreter starting and stopping the terminal if you remover "'PST.Stop " on line # 68 it should be good to go. sorry.
    That fixed it. Working great now. Thanks!
  • jazzedjazzed Posts: 11,803
    edited 2011-03-18 17:15
    UltraLazer wrote: »
    Thanks @jazzed. I guess this is the kind of confusion one can anticipate with a language who's name must be bowdlerized. Oh well, mostly for learning.
    I just though it was interesting that more than one person would do a BF interpreter :-). I'm not into Genetic Algorithms, but if there is demonstrable value for BF in that field, that's great. For GA I suppose it doesn't matter if something is human readable or not. Learning to read and write BF code was interesting though.

    Cheers.
    --Steve
  • UltraLazerUltraLazer Posts: 30
    edited 2011-03-18 17:44
    Yahhh, I thought it was interesting that BF (with infinite memory) is Turing complete, and yet it so simple. There is another one called P" I think that has only 6 instructions and lacks input and output... I guess its "output" is how long the program takes to terminate?

    I did a simple GA optimization in spin, but optimizing the GA it self is very difficult outside of tweaking a few parameters (mutation rate, initial population etc). I thought it might be possible to code the fitness function for the spin GA in BF. This way the function that decides which genes survive has the chance to evolve it self. The prop could generate, run and evaluate BF fitness functions. Then the issue it the meta fitness function...
Sign In or Register to comment.