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

×
high rated
EDIT on 29th June 2017:

A new version of this is available:
https://www.gog.com/forum/general/my_new_and_improved_gogcom_brainfck_quine_v2
https://www.youtube.com/watch?v=ob2zLvE23Lo
http://www.zbalbous.com/bfgogquine.html

Original version below:

-------------------------------------------------------------------------------------

So I was looking for ideas for my next esoteric challenge, and I thought maybe I could do something with quines. Unfortunately I couldn't come up with any original and interesting ideas of hiding the game key (ones that I didn't already use before in my previous two challenges). I thought a bit of creating a quine with GOG.com logo in it and the game key hidden somewhere, but again the key-hiding puzzle itself was either too easy or too complicated or just boring.
While looking around I stumbled upon a globe quine done in Ruby by Yusuke Endoh, and I thought it would be a cool idea to do something like that in brainfuck. So after a bit of work I finally managed to complete it. Here is my first attempt. Unfortunately the code is a bit (or a lot) too verbose.

http://www.zbalbous.com/bfgogquine.html

It's brainfuck code that prints itself, except that the globe part of the code gets rotated by 1/50th of a circle. After 50 iterations you get the original code. So it's an iterative-quine that works like: code0 -> code1 -> code2 -> ... -> code48 -> code49 -> code0 -> etc.

To visualise it, here is a youtube video that's basically a slideshow of the codes put together. In essence every frame is valid brainfuck code that outputs the next frame.

https://www.youtube.com/watch?v=ws-bRLdMJrs

As I said, initially I was thinking of putting a GOG.com logo in the code. After I decided to create a globe instead, the logo's fate was to be shrunk and put somewhere in the south Atlantic.

While working on it, I thought it would be an interesting challenge to add another restriction to it. As those familiar with brainfuck know, a period (.) is used for outputting a character at the data pointer. So my restriction was:

_The code should contain only one period.

As you can see, my code indeed does contain only one, neatly hidden in my email.

If you want to run the code, note that:
_It uses 8-bit size cells (which I believe is the usual implementation).
_You need a memomry size of 170,000 (!). 165317 to be exact. Note that most brainfuck implementations use a default of 30,000 memory size, so make sure change that, else the code won't run properly.
_It's very slow. I never optimized it for speed or memory. Far from it in fact; I tried to make the code itself small (whether I suceeded is a different story), so I'd often be content with taking a huge performance hit if it meant shaving off a few bytes of the code here or there.

You can try running the code in this online interpreter
https://copy.sh/brainfuck/
Remember to change memory size to 170000 first. Or use Dynamic memory but that will make it even slower. It runs about 3 minutes on my machine. Other online interpreters out there might not even run it. A better idea would be to look for faster interpreters (just remember about the memory). I used one writtern in C# that works by translating the brainfuck commands to their C equivalents.

Also, you will need a monospace font of course to see the output properly. Depending on what font you use the globe might be a bit stretched. I used Lucida console in the video.

You can download the raw source code here
http://www.zbalbous.com/bfgogquine.b
Just note that there are 255 characters per line, and at default font size and the usual screen resolution, most browsers would wrap it so you won't see it properly. Zoom out/decrease fot size to see it.

So that's it. Unfortunately this means that there won't be any esoteric challenge for the time being.

I'll come back to this when I have more time. I have a few ideas on how to make the code much smaller, but that would mean doing a lot of it back from scratch (and abandoning my 1-period-only rule). So I'll need to wait till I have more spare time.

Credits:
_A huge huge thank you to Yusuke Endoh's Qlobe for the idea and inspiration. Unfortunately I do not know Ruby, but his quine convinced me to try copy his idea in brainfuck.
http://mamememo.blogspot.ie/2010/09/qlobe.html
_Thanks to Erik Bosman's famous 410-byte quine.
Post edited June 29, 2017 by ZFR
EDIT, aaargh, I hope the code page dispalys properly in your browser without unnecessary line wraps. Here is what I'm aiming for, but it doesn't seem to be always the case.
Attachments:
quine.png (164 Kb)
Wow. That must have taken a hell of a lot of time. I applaud the effort you go to with these esoteric programming languages, I struggle enough programming in languages designed to be easy to use...

Can't say I'm not a little disappointed it's not a puzzle though ;P
That is outright crazy...

I know Brainfuck was made with the minimum number of symbols/instructions, but it requires so much overhead to get any work done that you can't go back and re-write or fix anything if there's an issue later. Sorta why other languages that used all 256 symbols to denote special meanings also ended up abandoned even if they were fairly powerful.

Was the code written with a flat map used and wrapped around? Or was it written with 50 stored partial images? Actually the full map would probably be smaller, but it's state certainly seems like a tricky thing to deal with.

Regardless, outright crazy :P

edit1:
avatar
ZFR: _It uses 8-bit size cells (which I believe is the usual implementation).
Actually that pretty much answers my question...

edit2: Actually watching the video again and seeing how it would play out, i see it's a fixed image and not calculated using sine or other heavy mathemetics. But with such small resolution that wouldn't work either :P

I remember years ago writing a fractal program that output a zoom but did it as Ascii, then using the editor just hit page-down to watch the individual frames and as the zoom went to some predetermined point until the zoom level couldn't go any deeper due to 32bit limits...

Wow, that brings back memories...
Post edited July 10, 2016 by rtcvb32
avatar
adaliabooks: Wow. That must have taken a hell of a lot of time.
As you are probably familiar with when writing programs, the bulk of the program was done relatively quickly. Then a much much longer time was spent doing the tiny little details. Little stuff that wasn't necessary and might not be really noticed, but I thought it'd be nice to have. Like line breaks, (almost) equal length lines, having the code wrap nicely around the globe...

For example, one cell stores the iteration counter of the map, for 5 iterations it can be done easily so:

//0
+ //1
++ //2
+++ //3
++++ //4

But this would mean that the code won't be of equal length, so the code will be longer or shorter depending on the iteration. To solve it you have to go

----++++ //0
---+++++ //2
--++++++ //4
-+++++++ //6
++++++++ //8

Now all code is of equal length and the line in all iterations will be of equal length, but it is more complicated to do this, plus you have to remember that in this case iteration will be storing twice the value.

At this stage somewhere my only-one-period rule was really hurting me, but I was too far gone with it, that I wanted to see it through the end. Finally came the stage when I saw how large the final product was and started trying to reduce its size. I did this for a bit, till deciding to give it a rest. There was only so much I could do without major code restructuring, and one extra line of code won't really make all that difference.
avatar
adaliabooks: I applaud the effort you go to with these esoteric programming languages, I struggle enough programming in languages designed to be easy to use...
Yeah, too bad mine is not really the stuff that's useful to put on CVs. I'm sure a potential employer would appreaciate much more the skills that went into creating Adalia Fundamentals than into a rotating brainfuck quine ;)
Here is a challenge:

Write a program (in another language) to generate the quine. Have it use AI techniques to find one that's short and reasonably fast.

(Note that the lack of a solution to the halting problem makes this problem non-trivial; checking every possible program for the shortest solution takes forever because some programs don't halt.)
avatar
rtcvb32: Was the code written with a flat map used and wrapped around? Or was it written with 50 stored partial images? Actually the full map would probably be smaller, but it's state certainly seems like a tricky thing to deal with.
Just one flat map image wrapped around. Stored by counting consecutive black and white pixels in a line (e.g. 5 black pixels followed by 3 white ones would be stored as 5,3).

By the way, of the 170k of tape length required, storing the image was done in only a tiny fraction. A lot of that was just wasted space, which was a consequence of me trying to shorten the program.
e.g. it was shorter to create a 255 bytes "array" even if I wanted a tiny one, and then just use what I want and have the rest of space go to waste, because you can store 255 with just one character "-" while storing the value you really needed would have taken more characters.
avatar
rtcvb32: i see it's a fixed image and not calculated using sine or other heavy mathemetics. But with such small resolution that wouldn't work either :P
Pretty much this. It's not a real rotation calculated using mathematics. There were no calculations done for example to calculate the width of the landmass based on its angle (it should appear much wider at the center than at the edges), but at this resolution this is good enough.
It's an ugly code in reality. I "cheated" often. In many cases it was easier to just hard code some values, than the "neater" way of calculating them using mathematical formulas.
Post edited July 10, 2016 by ZFR
avatar
ZFR: Pretty much this. It's not a real rotation calculated using mathematics. There were no calculations done for example to calculate the width of the landmass based on its angle (it should appear much wider at the center than at the edges), but at this resolution this is good enough.
It's an ugly code in reality. I "cheated" often. In many cases it was easier to just hard code some values, than the "neater" way of calculating them using mathematical formulas.
Emulating floating-point would have been a pain anyways. You'd have to do a lot of similar stuff that the 8bit computers did with 6 byte numbers using BCD and complex calculations. I can't even consider how big that would be...
It's great that you took the time and effort to create this. Kind of reminds me of the old demo scene stuff of old (in the sense that it's a lot of effort to make something this complicated).
Wow, nice work! :)
avatar
ZFR: *snip*
I am amazed as always ;-)

Regarding the quine idea, how about a cross-language quine? By that I mean a program which outputs a program in another language, which in turn outputs the first program again. Or for that matter, a whole string of them, changing syntax for each execution. You know, a C# program which outputs a Brainfuck program which outputs a Java program which outputs a Perl program which outputs the original C# program.

Might be an interesting challenge.
avatar
Wishbone: Regarding the quine idea, how about a cross-language quine? By that I mean a program which outputs a program in another language, which in turn outputs the first program again. Or for that matter, a whole string of them, changing syntax for each execution. You know, a C# program which outputs a Brainfuck program which outputs a Java program which outputs a Perl program which outputs the original C# program.
100 language uroboros.

With a png of the code:
https://github.com/mame/quine-relay/blob/master/thumbnail.png
Post edited July 11, 2016 by ZFR
avatar
Wishbone: Regarding the quine idea, how about a cross-language quine? By that I mean a program which outputs a program in another language, which in turn outputs the first program again. Or for that matter, a whole string of them, changing syntax for each execution. You know, a C# program which outputs a Brainfuck program which outputs a Java program which outputs a Perl program which outputs the original C# program.
avatar
ZFR: 100 language uroboros.

With a png of the code:
https://github.com/mame/quine-relay/blob/master/thumbnail.png
Hehe, I should have known :-D
avatar
ZFR: As you are probably familiar with when writing programs, the bulk of the program was done relatively quickly. Then a much much longer time was spent doing the tiny little details.

Yeah, too bad mine is not really the stuff that's useful to put on CVs. I'm sure a potential employer would appreaciate much more the skills that went into creating Adalia Fundamentals than into a rotating brainfuck quine ;)
Heh, for me it's usually write the program quite quickly, then spend weeks trying to figure out why it doesn't work / do what I wanted it to / do what I expected it it to do.
Or spend weeks figuring out how to do whatever I want at all and then write the program quite quickly...

Possibly... shame I didn't do it when I could have used a job in programming. Now that I'm happily self employed a CV isn't much use... though if I could make some money from programming in my free time that would be great.
And if I was hiring someone I'd choose you over me, but then I know most of my programs are cobbles together from answers on StackOverflow... ;)
no brainfucks please, I had to write something nice about Dalthnock and my head still hurts from that.