Small Brainfuck

Discussion of challenges you have already solved
User avatar
Hippo
Posts: 339
Joined: Sat Feb 01, 2014 12:05 am
Location: Praha 5

Post by Hippo »

BTW: What character is on position 06 of the mentioned code?
Is it's ascii 31? OK, it must be ... I like the idea <>+- are almost the same command with parameters (-1,0),(1,0),(0,1),(0,-1) ... (computed from opcodes rather than tabulated). I must say I am a bit confused by the PC going the central path in both directions ... I really cannot imagine how you could invent it. I have not studied the memory layout thoroughly ... of course I know the 00-0X is the simulated brainfuck code (with ! or \0 at the end) and (10-) are brainfuck registers. As the PC and MP are on stack, you must do rather uneffective 3v3v3v and 2v2v sequences.
I don't know if the only problem is the cycle limit.
Last edited by Hippo on Tue Aug 16, 2016 9:46 am, edited 1 time in total.
User avatar
Hippo
Posts: 339
Joined: Sat Feb 01, 2014 12:05 am
Location: Praha 5

Post by Hippo »

Wow congrats a.goth, you are definitely the brainfuck king :). (Both small and fast solutions).
BTW: what is roughly the size of the fast one?
a.goth
Posts: 43
Joined: Sat Sep 14, 2013 10:39 am

Code size

Post by a.goth »

Thanks for the congratulations!

My solution to challenge 'Super Fast Brainfuck' has code size 1885, but the SuperHack program consists of only 447 instructions. Furthermore, I still see room for improvement.
a.goth
Posts: 43
Joined: Sat Sep 14, 2013 10:39 am

Nested loops

Post by a.goth »

Hippo wrote:Oh OK simple is relative :). Your compiller cycle solution was hard to extend to nested loops, my original layout works for arbitrary level of nesting (level 4 is max, but starting on line 9 would allow levels upto 9).
I think I may have found a simpler way to compile nested loops:

Code: Select all

                  [/?x         [/?x                \s0        \s0
%00  }1+}1+}1+  x?s\    }1+  x?s\    1-{1+1+1+}  x?/    {{  x?/    }xp  !
                 1s\          1s\                x1:?       x1:?
It is the compilation of the following Brainfuck program:

Code: Select all

>+>+>+[>+[-<+++>]<<]>.
What do you think about it?
a.goth
Posts: 43
Joined: Sat Sep 14, 2013 10:39 am

Single-line loops

Post by a.goth »

Hippo wrote:One liner for general while cycle is impossible. Oneliners are possible for cycles of known maximal number of repetitions. ... oh there is 300 brainfuck rounds limit ... so may be ...
I have been thinking about it, but even with this restriction single-line loops are not possible. However, I have found a way to compile even nested loops in just two lines:

Code: Select all

...  s/x?@s\x?s\  ...  s/x?@s\x?s\  ...   $/   ...   $/   ...
     s\ss1s/  s\       s\ss1s/  s\       x1:?       x1:?
Is it possible to simplify this further?
User avatar
Hippo
Posts: 339
Joined: Sat Feb 01, 2014 12:05 am
Location: Praha 5

Re: Single-line loops

Post by Hippo »

a.goth wrote:

Code: Select all

...  s/x?@s\x?s\  ...  s/x?@s\x?s\  ...   $/   ...   $/   ...
     s\ss1s/  s\       s\ss1s/  s\       x1:?       x1:?
Is it possible to simplify this further?
I must say I like it :) it simplifies the compiler as it does not need threads to fill empty space.
And it even saves time as it skips walks back in cycles.

Thanks to $' it would be even possible to incorporate computed speedups on the fly.

([->++++<] compilation which adds to > 4 times . and clears . and so)

I just don't think theses speedups would be interesting in cases with at most 300 brainfuck cycles.
Post Reply