## Befunge Brain Teasers

15

### Introduction

For the ones wondering what Befunge exactly is, it is a two-dimensional stack based language made in 1993 by Chris Pressy. I made 7 brain teasers that need to be solved in Befunge-93. This is quite an experimental challenge, but I thought it's worth a shot :). A full list of all commands used in Befunge-93 can be found here.

### How to play?

The task is a bit like a cops-and-robbers without the cops. It's just basically cracking submissions in order to get points. Every puzzle contains question marks. These must be replaced by any printable ascii character in the range 32 - 127, that includes whitespace. See the following example:

??????@


Given is that the output must be hi. After some puzzling, we can find out that the solution was:

"ih",,@


But! You do not give the solution. That is for the prevention of cheating. You don't post the solution, but the hash. The hash is generated with the following snippet:

String.prototype.hashCode = function() { var namevalue = document.getElementById("inputname").value;  var namenumber = 123;for (var character = 0; character < namevalue.length; character++) {namenumber += namevalue.substring(0, 1).charCodeAt(0);}var hash = 123 + namenumber, i, chr, len;if (this.length === 0) {return 0;}for (i = 0, len = this.length; i < len; i++) {chr = this.charCodeAt(i);hash = ((hash << 5) - hash) + chr; hash |= 0; }hash = Math.abs(hash);if ((hash).toString(16).length < 20) {for (var rand = 123; rand < 199; rand++) {hash = hash * rand;if ((hash).toString(16).length >= 20) {  break; }}}return (hash).toString(16).substring(2, 12);};function placeHash() { var pretext = document.getElementById("inputhash").value; var resultinghash = pretext.hashCode(); document.getElementById("resulthash").innerHTML = 'Your hash: <span class="hashtext">' + resultinghash + "</span>";}
p {font-family: monospace;color: black;} .hashtext{color: red;font-weight:bold}
<div class="container"><p>Personal hash generator:<p><textarea id="inputhash" placeholder="Your submission" cols="40" rows="4"></textarea><br><textarea id="inputname" placeholder="Your name" cols="40" rows="1"></textarea><br><button class="hashbutton" onclick="placeHash()">Generate Hash!</button><br><p id="resulthash">Your hash:</p></div><!-- Created by Adnan -->

### How to use the snippet?

• First, paste the solution into the submission section
• Second, enter your username (nothing else, this will actually be verified after the time limit)
• Third, press Generate Hash! to obtain your personal hash.
• Copy and paste the hash into your submission.

### The puzzles

Puzzle 1 (Score: 3)

 ??
???      ?
??????????
@


Output (note the trailing whitespace):

1 2 3 4 5 6 7 8 9 10


Puzzle 2 (Score: 3)

 ????    ?
??????????
??       ?
@


Output:

abcdefghijklmnopqrstuvwxyz


Puzzle 3 (Score: 5)

  ?????????
?????  ???
?     ?
? ?   ?  ?
?
?  ?
??????  ?  ?
?     ?  ?
?  ?  @
??????? ?
?  ?
????  ??
?  ??


Output:

Hello World!


Puzzle 4 (Score: 2)

??????@


Output (note the trailing whitespace):

123


Puzzle 5 (Score: 5)

    ?
?????
???@?????
??????
?????????


Output:

Befunge


Puzzle 6 (Score: 5)

?    ?   ?
?
??????????
?
?
????????                         ??????????????
?????"floG edoC dna selzzuP gnimmargorP "??????
@


Output:

###################################
Programming Puzzles and Code Golf
###################################


Puzzle 7 (Score: 3)

???? ?????
???????
@???????


Output:

012345678910


• This is , the person with the most amount of points wins!
• In case of a tie, the person who submitted all submissions first, wins.
• The last day for submission is January 10 UTC. After that, you have 2 days to post the full solution, with the hashes already included. These will be verified :).

### How to post?

Use the following snippet to post your submission:

#N solutions:

Puzzle 1: [hash 1]

Puzzle 2: [hash 2]

etc.


It is not necessary to solve the puzzles in order. All programs have been tested here and will be used for verification.

Good luck!

I suppose it's fine if we remove trailing whitespace (in case we replace any of the trailing ? with spaces)? – Martin Ender – 2016-01-03T18:25:43.483

Are you sure there's a unique solution for each puzzle? – KSFT – 2016-01-03T18:29:35.627

@KSFT Does it matter if the solutions are unique? – Martin Ender – 2016-01-03T18:30:06.787

@MartinBüttner If it isn't unique and someone gives a different solution, the hash won't match. – KSFT – 2016-01-03T18:32:19.717

@KSFT The hashes won't match anyway, because the user name is part of the hash. The purpose of the hash is only to verify who found a working solution first. – Martin Ender – 2016-01-03T18:32:55.090

@KSFT No, but that is not relevant. The hash will only be used to verify submission and the submission itself will be verified here.

@Adnan Yes, replacing ? with spaces is find, but what I'm asking is whether I can omit trailing spaces after doing so. (As well as trailing empty lines.) – Martin Ender – 2016-01-03T18:44:22.750

@MartinBüttner Yes, trailing whitespaces (and trailing empty lines) may be deleted as they are considered to be no ops. – Adnan – 2016-01-03T18:48:14.970

Should the hashes be salted with additional random text that the people posting solutions keep secret? As it is, it doesn't seem hard to brute-force to find other people's posted solutions. – KSFT – 2016-01-03T19:19:03.650

@KSFT That doesn't seem necessary. You can try to brute-force it, but I'm pretty confident it would take a long time for just one hash. – Adnan – 2016-01-03T19:25:44.010

Just clarifying, there is no trailing space on puzzle 7? – Martin Ender – 2016-01-03T21:05:12.610

@MartinBüttner Nope. – Adnan – 2016-01-03T21:06:04.920

May I replace ?s by ?s? I'm coding on a phone and I'm lazy. :P – PurkkaKoodari – 2016-01-04T19:57:48.393

@Pietu1998 Yes, that is possible :). (note that the ? is a random operator in Befunge) – Adnan – 2016-01-04T20:00:01.350

Do any of your solutions make use of interpreter's non-standard behaviour that it reflects the IP when encountering unknown commands? – Martin Ender – 2016-01-05T08:56:18.393

@MartinBüttner If I remember correctly, that is not used. – Adnan – 2016-01-05T08:59:24.120

If I understood correctly, now is the time to reveal our solutions, right? You might also want to notify @MartinBüttner about that. – PurkkaKoodari – 2016-01-11T19:12:22.493

@Pietu1998 Yes, that is correct – Adnan – 2016-01-11T19:28:24.623

5

# 7 solutions, 26 points

I'm typing this on my phone, because I don't have access to my computer currently. I actually had to work out Puzzle 6 by pen & paper.

### Puzzle 1 (Score 3): 4f52d5b243

 1v
v:<      <
>.1+:56+-|
@


This one is fairly straight forward. Get a 1 on the stack, then print-increment-compare-loop until 11 is hit.

### Puzzle 2 (Score 3): 85226eba20

 ""     v
v"z":,:+1<
>-       |
@


Basically the same as the previous one, just with characters instead of numbers. Used a different IP route though.

### Puzzle 3 (Score 5): 1ff5bcb1d9

  "!dlroW"v
>,,,,  ,,v
,     "
, ?      ,
o
l
??,???  l
,     e
?  "  @
??^,"H" <
?  ?
????  ??
?  ??


Here I cheaped out a little bit. Push the string to the stack and print characters manually, navigating through the spaces. I had loads of extra room, so I just left most of the question marks in. Note the trailing spaces on rows 6 to 8, I didn't remove them when calculating the hash.

### Puzzle 4 (Score 2): f8b7bdf741

"{".  @


Really simple, just get the character with the correct code and print as a number, with two free spaces.

### Puzzle 5 (Score 5): c4db4b6af9

    v
??"??
#,_@e">>:
<"B"<^
ung"<^"ef


This was a fun one to get right. May not work correctly on some interpreters due to wrapping strings & jumps, works on the linked one. Basically, the code pushes the output string and then enters the standard printing loop, wrapping on the sides.

### Puzzle 6 (Score 5): 356e912eec

1        v
#
v??v_

5
75<^                              p15:-1g15,:*
>5+:,"floG edoC dna selzzuP gnimmargorP ">:#,_@
@


Now this was the "masterpiece". I actually took a piece of paper and spent some time on this. (Actually, I did some extra work by missing the space in the string when copying.) Note the trailing spaces on row 4, I didn't remove them when calculating the hash.

The code works by first pushing a one to enter the main loop. The loop uses the # on the second line as a counter, and both prints and pushes a # on every iteration. After that a newline is printed and pushed. Next, the given string is pushed. Finally, the code enters a printing loop, which prints everything on the stack in reverse, which means the string, then the newline, and finally the remaining #s.

### Puzzle 7 (Score 3): 0881fc2619

"0"> :,1+v
|-":":<
@>"10",,


This is almost the same as Puzzle 2, but with a different route, different output characters, an additional 01 in the end and a quick wrap to finish it off.

Haha, I should have thought a bit longer for the puzzle 3 and 4. Everything looks good :) – Adnan – 2016-01-11T19:52:12.683

3

## 4 solutions, 15 points

I hope I didn't mess up the trailing whitespace anywhere when generating the hashes.

### Puzzle 1 (Score 3): de1de4c4c8

 v
v<       >
>1+:.:9!|
@


### Puzzle 3 (Score 5): 071cad0879

  "!dlroW"v
>,,,,  ,,v
,     "
,        ,
o
l
,     l
,     e
"  @
^,"H" <


### Puzzle 4 (Score 2): 531940bc43

"{".  @


### Puzzle 5 (Score 5): 5bafaed8e9

    ^
v >,,
n"<@,, ,"
"e"^>,
uge"<^"Bf