r/code • • Jul 29 '16

Help Please Please help! Need code to announce our pregnancy to my programmer boyfriend... <3

Hi all, my boyfriend is a Senior Software Engineer... I just found out that we are expecting, and I'd love to break the news to him with a block of code! Trouble is, I don't code... Would you all help me write a small block of code to let him know he's going to be a daddy? TIA!

1.3k Upvotes

209 comments sorted by

View all comments

193

u/Poromenos Sep 04 '16

Write one in Brainfuck, if you're lucky he'll figure it out before the baby arrives.

161

u/BACON8000 Sep 04 '16

+++++++++++++++++++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.<++++++++.-------->++++.<.>+++.++.-------------.++.+++++++.-------------.+++++++++++++.++++++.

http://imgur.com/PCUTnFD

42

u/Miodec Sep 04 '16

TIL this is a thing

40

u/BACON8000 Sep 04 '16

It's not as complicated as it sounds to be honest. You just have to interpret it in your brain and it's quite simple, simple enough to write in a Costa Coffee carpark with a crying baby in the back of the car.

So, to begin with, brainfuck uses pointers and values. A pointer is like saying which particular value are we working with, and the value is the actual...you know...value of that particular pointer. > and < move your "current pointer" up and down, or left and right, however you like to see it. + and - increment/decrement the value of that pointer (default is 0). . prints the current value out as ASCII.

So, first I initialise the first pointer to 32, the ASCII for space (for later): +++++++++++++++++++++++++++++++.

Then I move to the next pointer > and increment it right up to 105 (ASCII for "i") and print that out: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.

After that, I switch back down to the space I prepped earlier, < and increment it up to 39 for a comma, which I print, ++++++++. before returning that back down to 32 for the space --------.

I switch back to my other pointer > and add four to the previous value for m, which I print ++++..

I switch to the other pointer which holds a space and print it, and move back to my other pointer, which is at m: <.>.

I then increment m to p and print +++., then on to r and print ++., then all the way back to e: ------------- and print ..

So now we're at i'm pre, next we need g, ++., and then n, +++++++..

Now we need ant, so, back to a: -------------., forward to n: +++++++++++++. and finally, pop a t on the end: ++++++.

As you can see, if you know the alphabet and the ASCII table (http://www.asciitable.com/index/asciifull.gif) then you can write it on your phone while a baby cries and your girlfriend talks to you (blocked out) without much effort.

5

u/iauu Sep 04 '16

I thought it was much more complicated than that! Maybe it's the fact that it doesn't have any obvious new line or distinct character separating instructions.

Thanks for the explanation!

4

u/phatskat Sep 04 '16

Awesome explanation of brainfuck! Out of curiosity, how would you code a simple if like

if ( X ) { echo "Hi!"; }

1

u/GreyVersusBlue Sep 04 '16

So.... You're writing on two sides of a point, simultaneously, and each time you jump from side to side you're writing a new character? And the character is based on a value determined by the +s and -s?

1

u/bcgoss Sep 04 '16

A pointer is a reference to a memory address. It "points" to that byte and says 'this one'. In brainfuck when you use + or - you change the value of the memory you're pointing to. The period symbol is used to read the memory at the current pointer and interpret it as an ascii character to be printed on the screen.

The < and > symbols are used to switch the pointer you're working with. Your program starts off with pointer 0, and you can use > to switch to pointer 1, then do some stuff and use < to switch back to pointer 0. This is useful because you can make changes to Pointer 0 without affecting pointer 1. You can set one pointer to the ascii value of a symbol and the other to point to the letter m. That way you don't have to step the value of the pointer all the way down to 32 just to use a space.

1

u/GreyVersusBlue Sep 04 '16

Alright. I think I understand it.

So what would be a practical reason to use this, rather than more traditional code?

→ More replies (3)
→ More replies (2)

6

u/BACON8000 Sep 04 '16 edited Sep 04 '16

Wait till I get home.

Fuck it. I'll do it now but I'm on my mobile so bear with me. http://imgur.com/bZtHBuk

6

u/MadCervantes Sep 04 '16

Oh man. Someone do this please. I just want to see what that would look like.

19

u/not_an_evil_overlord Sep 04 '16
++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++>++++++++++++>+++++++++++++>++++++++++++++>+++++++++++++++>++++++++++++++++<<<<<<<<<<<<<<<<-]>>>>>>>>>>>-.+<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>-.+<<<<<>>>>>>>>>>>>>>++.--<<<<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>.<<<<>>>>>>>>>>>>>>.<<<<<<<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<<<<<<<<<<<<>>>>>>>>>>>>>-.+<<<<<<<<<<<<<>>>>>>>>>>>>+.-<<<<<<<<<<<<>>>>>>>>>>>>>+.-<<<<<<<<<<<<<>>>>>>>>>>>>>>--.++<<<<<<<<<<<<<<>>>>+.-<<<<.

3

u/Sulpiac Sep 04 '16

/u/compilebot brainfuck

9

u/not_an_evil_overlord Sep 04 '16

+/u/CompileBot brainfuck

++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++>++++++++++++>+++++++++++++>++++++++++++++>+++++++++++++++>++++++++++++++++<<<<<<<<<<<<<<<<-]>>>>>>>>>>>-.+<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>-.+<<<<<>>>>>>>>>>>>>>++.--<<<<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>.<<<<>>>>>>>>>>>>>>.<<<<<<<<<<<<<<>>>>>>>>>>>>>>++.--<<<<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>>>>>>>>>-.+<<<<<<<<<<<<<>>>>>>>>>>>>>>--.++<<<<<<<<<<<<<<>>>>>>>>>>>>+.-<<<<<<<<<<<<>>>>>>>>>>>>>>--.++<<<<<<<<<<<<<<>>>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<<<>>>>>>--.++<<<<<<>>>>.<<<<>>>>>>>>>-.+<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<<<>>>>.<<<<>>>>>>>>>>>>>>++.--<<<<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>>>>>>>>+.-<<<<<<<<<<<<>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<>>>>>>>>>>>>>>>+.-<<<<<<<<<<<<<<<>>>>.<<<<>>>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<<<>>>>>>>>>>>>>>-.+<<<<<<<<<<<<<<>>>>.<<<<>>>>>>>>>>>>>-.+<<<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<<<>>>>.<<<<>>>>>>>>>>>>++.--<<<<<<<<<<<<>>>>>>>>>>>>>>++.--<<<<<<<<<<<<<<>>>>>>>>>>>>+.-<<<<<<<<<<<<>>>>>>>>>>>>>+.-<<<<<<<<<<<<<>>>>>>>>>>>>>>--.++<<<<<<<<<<<<<<>>>>>>>>>>>>>--.++<<<<<<<<<<<<<>>>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<<<>>>>>>>>>>>>+++.---<<<<<<<<<<<<>>>>>>>>>>>>>+++.---<<<<<<<<<<<<<>>>>>>>>>>>>>---.+++<<<<<<<<<<<<<>>>>>>>>>>>>>----.++++<<<<<<<<<<<<<>>>>.<<<<>>>>>>>>>>>>+.-<<<<<<<<<<<<>>>>>>>>>>>>>-.+<<<<<<<<<<<<<>>>>>>>>>>>>+.-<<<<<<<<<<<<>>>>>>>>>>>>>+.-<<<<<<<<<<<<<>>>>>>>>>>>>>>--.++<<<<<<<<<<<<<<>>>>+.-<<<<.

23

u/CompileBot Sep 04 '16

Output:

We're pregnant. Get ready to get brainfucked again!

^source | ^info | ^git | ^report

4

u/not_an_evil_overlord Sep 04 '16

Neat! Didn't know about this bot.

+/u/CompileBot C

#include <stdio.h>
int main() {
    printf ("%08x %08x %08x %08x %08x\n");
    return 0;
}

4

u/CompileBot Sep 04 '16

Output:

ffb2d924 ffb2d92c 5569fe4d 557dc3a4 ffb2d890

^source | ^info | ^git | ^report

4

u/not_an_evil_overlord Sep 04 '16

So, is each execution isolated? Can you do multiple executions per comment? Are they serially executed?

+/u/CompileBot C

#include <stdio.h>
int main() {
    printf ("%08x %08x %08x %08x %08x\n");
    return 0;
}

+/u/CompileBot C

#include <stdio.h>
int main() {
    printf ("%08x %08x %08x %08x %08x\n");
    return 0;
}

2

u/CompileBot Sep 04 '16

Output:

ffacda14 ffacda1c 556ace4d 557e93a4 ffacd980

^source | ^info | ^git | ^report

→ More replies

1

u/Sulpiac Sep 04 '16

Thanks for that

0

u/[deleted] Sep 04 '16

[deleted] — view deleted comment

3

u/BACON8000 Sep 04 '16

Malbolge

sorry, not on my phone

2

u/kh4yman Sep 04 '16

You're evil. I like you.

→ More replies (1)

1

u/BACON8000 Sep 04 '16

Sorry it took a while...got a baby with me.

head in hands