DO NOT DEAL WITH THIS MEMBER
What's up HF, today I have a challenge for you... I know you probably think it's impossible just because you saw the words "Brainfuck". Well guess what? It's actually pretty easy.
Your challenge is to create a function (in any language you like) that takes a string as a parameter and prints out Brainfuck code that will compute that string.
Use this to test your code: https://copy.sh/brainfuck/
How Brainfuck works: https://www.youtube.com/watch?v=-3C200nCwpk
First person to post a working solution gets the prize. Bonus points for having less lines of code (and don't try to shorten code by compressing everything to one line; you must have new lines after semi colons and at least three lines for if-statements, etc.)
Good luck! 🎉
Code ----[---->+<]>++.[--->+<]>+++.----------.-[--->+<]>-.---[->++++<]>.------------.---.--[--->+<]>-.[-->+++++++<]>.++.---------.------.++.--[--->+<]>-.-[--->++<]>-.++++++++++.[->+++++<]>.
DO NOT DEAL WITH THIS MEMBER
Dec 5, 2016 04:32 PM
(This post was last modified: Dec 5, 2016 04:42 PM by Insurmountable.)
Since I guess nobody can figure it out, I'll post my solution in Go.
(Dec 5, 2016 04:30 PM)Zilog80 Wrote: Code ----[---->+<]>++.[--->+<]>+++.----------.-[--->+<]>-.---[->++++<]>.------------.---.--[--->+<]>-.[-->+++++++<]>.++.---------.------.++.--[--->+<]>-.-[--->++<]>-.++++++++++.[->+++++<]>.
Lol, I don't need to buy your program, I've already made my own. It's a challenge.
Dec 5, 2016 04:47 PM
(This post was last modified: Dec 5, 2016 04:48 PM by Zilog80.)
(Dec 5, 2016 04:32 PM)Insurmountable Wrote: Lol, I don't need to buy your program, I've already made my own. It's a challenge.
Lol...the fucking smartphone grammar Dictionary wrote pri ce when I wanted to write "prize" (as you said in #1)
PHP Code
<?php
function toBrainfuck(string $string) { $result = ''; $letters = str_split($string);
foreach ($letters as $letter) { $ascii = ord($letter); $result .= str_repeat('+', $ascii) . '.'; $result .= str_repeat('-', $ascii); }
return $result; }
Obviously not the smarted way to do things, but you never said how it should work :p
DO NOT DEAL WITH THIS MEMBER
(Dec 5, 2016 04:47 PM)Zilog80 Wrote: Lol...the fucking smartphone grammar Dictionary wrote price when I wanted to write "prize" (as you said in #1)
If you want the prize, show your code!
Dec 5, 2016 05:19 PM
(This post was last modified: Dec 5, 2016 05:21 PM by LanMan.)
13lines, 199characters
DO NOT DEAL WITH THIS MEMBER
Dec 5, 2016 05:20 PM
(This post was last modified: Dec 5, 2016 05:22 PM by Insurmountable.)
(Dec 5, 2016 05:01 PM)PartTimeNinja Wrote: PHP Code
<?php
function toBrainfuck(string $string) { $result = ''; $letters = str_split($string);
foreach ($letters as $letter) { $ascii = ord($letter); $result .= str_repeat('+', $ascii) . '.'; $result .= str_repeat('-', $ascii); }
return $result; }
Obviously not the smarted way to do things, but you never said how it should work :p
Nice job, it's a helpful that PHP has a built in function for that.
(Dec 5, 2016 05:19 PM)LanMan Wrote: ![[Image: 5gCAn5a.png]](https://i.imgur.com/5gCAn5a.png)
13lines, 199characters
Ooh, good to see a solution in vanilla C. Nicely done.
Dec 5, 2016 05:28 PM
(This post was last modified: Dec 5, 2016 05:31 PM by PartTimeNinja.)
(Dec 5, 2016 05:20 PM)Insurmountable Wrote: Nice job, it's a helpful that PHP has a built in function for that.
Indeed.
Made it a bit shorter cause I can.
PHP Code
<?php
function toBrainfuck($string) { $result = ''; foreach (str_split($string) as $letter) { $ascii = ord($letter); $result .= str_repeat('+', $ascii) . '.>'; } return $result; }
Dec 5, 2016 05:28 PM
(This post was last modified: Dec 5, 2016 05:29 PM by LanMan.)
(Dec 5, 2016 05:20 PM)Insurmountable Wrote: Ooh, good to see a solution in vanilla C. Nicely done. Ye but the result is far from optimised haha 😁
And nice challenge, i didn't know about brainfuck !
Helloworld:
Code ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++.>
Next challenge should be the shortest brainfuck string result for a defined word/phrase !
DO NOT DEAL WITH THIS MEMBER
(Dec 5, 2016 05:28 PM)LanMan Wrote: Ye but the result is far from optimised haha 😁
And nice challenge, i didn't know about brainfuck !
Helloworld:
Code ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.>+++++++++++++++++++++++++++++++++.>
Next challenge should be the shortest brainfuck string result for a defined word/phrase !
Good idea! Have your program convert this phrase, try to get the shortest result:
Quote:Hello, world!
Code:
Code func v2_convert(s string) {
ascii := []byte(s)
for i := 0; i < len(ascii); i++ {
if i == 0 {
for j := 0; j < int(ascii[i]); j++ {
fmt.Print("+")
}
} else if ascii[i-1] > ascii[i] {
for j := 0; j < int(ascii[i-1])-int(ascii[i]); j++ {
fmt.Print("-")
}
} else if ascii[i-1] < ascii[i] {
for j := 0; j < int(ascii[i])-int(ascii[i-1]); j++ {
fmt.Print("+")
}
}
fmt.Print(".")
}
}
Result: 383 chars
Code ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------.+++.------.--------.-------------------------------------------------------------------.
... You posted a solution only 2 hours after you posted the thread...
DO NOT DEAL WITH THIS MEMBER
(Dec 5, 2016 09:09 PM)VmX5 Wrote: ... You posted a solution only 2 hours after you posted the thread...
I made the solution 15 minutes after learning brainfuck
Dec 6, 2016 04:10 PM
(This post was last modified: Dec 6, 2016 04:10 PM by LanMan.)
(Dec 5, 2016 07:20 PM)Insurmountable Wrote: Good idea! Have your program convert this phrase, try to get the shortest result:
Result: 383 chars
Code ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+++++++++++++++++++++++++++++.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------.+++.------.--------.-------------------------------------------------------------------.
Code:
![[Image: fV76w9R.png]](https://i.imgur.com/fV76w9R.png)
Result: 343chars !
Code +++++++++++++[>+++++<-]>+++++++.+++++++++++++++++++++++++++++.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------.+++.------.--------.-------------------------------------------------------------------.
DO NOT DEAL WITH THIS MEMBER
(Dec 6, 2016 04:10 PM)LanMan Wrote: Code:
![[Image: fV76w9R.png]](https://i.imgur.com/fV76w9R.png)
Result: 343chars !
Code +++++++++++++[>+++++<-]>+++++++.+++++++++++++++++++++++++++++.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------.+++.------.--------.-------------------------------------------------------------------.
Come on now, that's cheating! You have to generate everything programmatically!
|