It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
avatar
ZFR: From the Funge-98 specification.
http://quadium.net/funge/spec98.html
Whoops... I'd better not tell anyone that that page holds the exact same information as https://github.com/catseye/Funge-98/blob/master/doc/funge98.markdown that is being linked to from the bottom of the wikipedia article I mentioned... I'm pretty sure I even skimmed over that specific entry. Not quite the programmer yet, I'm afraid. It also took me a few hours to come up with the code that I will post in a reply to chevkoch.
avatar
Namxas01: combined with the fact that the online interpreter that I found - brainfuck.tk - worked perfectly except from dumping the memory after running the code,
avatar
ZFR: Try this one.
https://copy.sh/brainfuck/

It has built in memory dumping.
Thanks, I'll check it out later. It doesn't play nice with my hellish IE11/W10 combo, informing me it requires javascript.
Somewhere during my BYOI (build your own interpreter) adventure, I also stumbled upon https://www.nayuki.io/page/brainfuck-interpreter-javascript. Not too shabby either.
avatar
chevkoch: Ages ago, I played around with BASIC on the C64. Messing with Brainfuck was really fun and got me a step closer motivation-wise to teaching myself some Python, which I've been thinking about for a while.
If you feel like thinking about Python in a different way, try throwing its name in this piece of code and see where it will guide you.
Post edited February 15, 2017 by Namxas01
avatar
Namxas01: If you feel like thinking about Python in a different way, try throwing its name in this piece of code and see where it will guide you.
Thanks for the link :)

By the way, your code contains an underflow. At one point the pointer moves to the left of cell 0 (When you use [<] to go to the first empty cell). It all works properly if the interpreter wraps the pointer around in this case, but that's not always the case, and should be avoided.

Try running it on this interpreter:
https://copy.sh/brainfuck/
It won't work if you don't use "wrap" from "Memory overflow behaviour" from the options on the right.

You can solve it by adding a single '>' to the beginning of your code. This basically shifts everything one cell to the right, so the underflow never happens.
avatar
ZFR: By the way, your code contains an underflow. At one point the pointer moves to the left of cell 0 (When you use [<] to go to the first empty cell). It all works properly if the interpreter wraps the pointer around in this case, but that's not always the case, and should be avoided.

You can solve it by adding a single '>' to the beginning of your code. This basically shifts everything one cell to the right, so the underflow never happens.
It's not just one overflow, I can tell you. It actually happened by chance (or one might say 'bad planning'). Looking for a place to store a value for a while, I used the very first cell. Since the interpreter I used didn't really seem to mind - I just had to compensate with a '>' to return from the other side - I didn't really miss my trusted origin. So the code holds quite a number of those (although most of them due to this same value). It didn't occur to me I could just have shifted all the memory values to the right, as per your remark.
Maybe I'll go and revise the code later today (or tonight after a couple of drinks) - see how that works out, having thrown away the original including comments and formatting. I do wonder how many characters and instructions that will save.
avatar
chevkoch: Ages ago, I played around with BASIC on the C64. Messing with Brainfuck was really fun and got me a step closer motivation-wise to teaching myself some Python, which I've been thinking about for a while.
avatar
Namxas01: If you feel like thinking about Python in a different way, try throwing its name in this piece of code and see where it will guide you.
Thanks much, this looks helpful. But had indeed to add a ">" at the beginning like ZFR suggested to make it work.
avatar
WildHobgoblin: I think the main problem for me was that I didn't really get results that indicated that I was on the right track whatsoever.
That was what I felt. Instead of several smaller steps, I felt this challenge had several large leaps. And I too went language hunting.
I'm not trying to diminish ZFR's amazing challenge here, just providing feedback.

I also agree about going up the complexity ladder when learning to program. It is like learning how to play chess starting by learning how to checkmate, then moving back to the late game, mid game and then openings, when the maximum number of pieces is in play. It also helps to grasp what is happening behind the scenes, that no magic or obscure things occur hidden away from view. Why can't I compare strings and numbers in the same way? Why is the original object changed when I change a copy of it? Why can't I grow arrays? And so on.
avatar
Gede: I also agree about going up the complexity ladder when learning to program. It is like learning how to play chess starting by learning how to checkmate, then moving back to the late game, mid game and then openings, when the maximum number of pieces is in play. It also helps to grasp what is happening behind the scenes, that no magic or obscure things occur hidden away from view. Why can't I compare strings and numbers in the same way? Why is the original object changed when I change a copy of it? Why can't I grow arrays? And so on.
That depends a lot on how you learn to program. When I studied computer science I was taught C++, and the course included explanations of CPU architecture, some assembly language, and how the various language features actually worked.

And if you ask why the original object is changed when you change a copy of it, the answer necessarily must be that you are not changing a copy of it, you are actually changing the original object. You may think you are changing a copy, but in all likelyhood what you have copied is a pointer to the object, not the object itself.
avatar
Wishbone: That depends a lot on how you learn to program. When I studied computer science I was taught C++, and the course included explanations of CPU architecture, some assembly language, and how the various language features actually worked.

And if you ask why the original object is changed when you change a copy of it, the answer necessarily must be that you are not changing a copy of it, you are actually changing the original object. You may think you are changing a copy, but in all likelyhood what you have copied is a pointer to the object, not the object itself.
We don't seem to disagree. That is still "bottom-up", and it makes sense. If you start with Smalltalk, and have no idea what a data structure is, how do you grasp the concept of "object" or "inheritance"? Yeah, you can still write some programs, but you will have a hard time understanding when things go wrong.

And about the pointer, yeah, the last time that happened I was left scratching my head for a while. "Oh, I get it! That makes a shallow copy!" That is just a new pointer. Duh!.
If I was to explain someone why some objects are passed by value while some other are passed by reference... it sounds so arbitrary unless you can understand what is happening behind the scenes.