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>>>>>>>>>>>>[<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<<<<[>[-]+<-]>[<+>>+++++++++++[>+++++++>++++++++++>+++++++++>+++>++++<<<<<-]>-.>+.+++++++.>++.<---.>>-.<<------.>.>.<<+.+.+++++.>>>++...[-]<[-]<[-]<[-]<[-]<++++++++++.[-]>>>>>>>[-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>>>>>>>->[-]<[>+<-][-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>>>>>>>>>[-]<<[<<<<<<+>>>>>>-]->>[<<<<<<<<-<+>>>>>>>>>-]<<<<<<<<<[>>>>>>>>>+<<<<<<<<<-]>[>>>>>>+<<<<<<[-]]<->>>>>>>[<<<<<<<->>>>>>>-]<<<<<<<[>>>>>>>+<<<<<<<-]>>>>>>>[>>>>>>>+<<<<<<<<<<<<<<<<->>>>>>>>>[-]]<<<<<<<<-]<[>[-]+<-]>[<+>>++++++[>++++++++++<-]>.-------------.++++.<<<<->>-]<<]
Pseudocode
loop
get a random byte
until random byte is >2 and <21
point to byte
[
output "Loves me..."
decrease byte by 1
if byte is 0
output "<3"
exit
eif
output "Loves me not..."
decrease byte by 1
]
output "</3"
Sample
When run, the program enters an interactive session waiting for input. Input should be a number. This number is used as a seed.
Seed: 1 (random number is 5, takes 218,168,042 operations)
1
Loves me...
Loves me not...
Loves me...
Loves me not...
Loves me...
<3
Seed: 3 (random number is 20, takes 463,253,048 operations)
3
Loves me...
Loves me not...
(...)
Loves me...
Loves me not...
</3
I'd suggest that you do not seed with 6
, as it takes 2,105,900,375
iterations to compute the result :).
Compiling / Running
You need a fast interpreter for this. No online interpreter I've tested could handle the execution speed. The ips (iterations per second) should be more than 100,000,000
. So I came up with another solution.
This is a Brainfuck to C compiler written in Brainfuck. You can use any online interpreter to transpile my code to pure C. I suggest using brainfuck.tk. Paste my code in the stdin input, past this code in the code input:
+++[>+++++<-]>>+<[>>++++>++>+++++>+++++>+>>+<++[++<]>---]>++++.>>>.+++++.>------.<--.+++++++++.>+.+.<<<<---.[>]<<.<<<.-------.>++++.<+++++.+.>-----.>+.<++++.>>++.>-----.<<<-----.+++++.-------.<--.<<<.>>>.<<+.>------.-..--.+++.-----<++.<--[>+<-]>>>>>--.--.<++++.>>-.<<<.>>>--.>.<<<<-----.>----.++++++++.----<+.+++++++++>>--.+.++<<<<.[>]<.>>,[>>+++[<+++++++>-]<[<[-[-<]]>>[>]<-]<[<+++++>-[<+++>-[<-->-[<+++>-[<++++[>[->>]<[>>]<<-]>[<+++>-[<--->-[<++++>-[<+++[>[-[-[-[->>]]]]<[>>]<<-]>[<+>-[<->-[<++>-[<[-]>-]]]]]]]]]]]]]<[-[-[>+<-]>]<[<<<<.>+++.+.+++.-------.>---.++.<.>-.++<<<<.[>]>>>>>>>>>]<[[<]>++.--[>]>>>>>>>>]<[<<++..-->>>>>>]<[<<..>>>>>]<[<<..-.+>>>>]<[<<++..---.+>>>]<[<<<.>>.>>>>>]<[<<<<-----.+++++>.----.+++.+>---.<<<-.[>]>]<[<<<<.-----.>++++.<++.+++>----.>---.<<<.-[>]]<[<<<<<----.>>.<<.+++++.>>>+.++>.>>]<.>]>,]<<<<<.<+.>++++.<----.>>---.<<<-.>>>+.>.>.[<]>++.[>]<.>[.---->.---,....]
Download the source and compile it:
gcc.exe -c main.c -o main.o
gcc.exe main.o -o loveme.exe
You can also run a copy of the C code online here: via. CodingGround.
Optimizations
There is still some work to do, but the cell re-use is almost optimal.
Remarks
You can use words or phrases as a seed:
Programming Puzzles & Code Golf
Loves me...
Loves me not...
Loves me...
Loves me not...
Loves me...
Loves me not...
Loves me...
Loves me not...
Loves me...
Loves me not...
Loves me...
Loves me not...
Loves me...
Loves me not...
Loves me...
Loves me not...
Loves me...
<3
Are there any restrictions on the distribution of the number of lines, i.e., should it be uniformly random, or is it enough that all lengths between 3 and 20 have a positive probability? – Zgarb – 2015-09-15T15:13:15.853
I didn't think about this, but I'd say that any distribution is fine - so they don't have to be uniformly random. – MatthewRock – 2015-09-15T15:14:26.947
Is it 3 to 20 (
[3, 20)
) or 3 up to including 20 ([3, 20]
)? – orlp – 2015-09-15T15:15:17.790@orlp Edited to adress that concern. 3 is minimum, 20 is maximum. So 20 lines is ok, but no 21. – MatthewRock – 2015-09-15T15:17:14.800
1@MatthewRock What if the language we want to use can't seed a random number on their own? Can the user supply a random seed? – mınxomaτ – 2015-09-15T15:35:55.933
@minxomat I'd prefer it to be random-random, so no user should generate randomness. Couldn't you get time or anything similar? – MatthewRock – 2015-09-15T17:31:42.547
@minxomat Are you trying to do this in Brainf*** or what? – mbomb007 – 2015-09-15T17:33:31.173
@MatthewRock No. There are a few languages that do not have support for timers. I'd like to require a seed from the user. I still have to implement a proper PRNG, so the challenge isn't easier for me. – mınxomaτ – 2015-09-15T17:43:20.600
@minxomat what language is it? – MatthewRock – 2015-09-15T17:50:36.123
@MatthewRock Brainfuck. – mınxomaτ – 2015-09-15T17:50:54.697
@MatthewRock let him take the seed as a input. – Mindwin – 2015-09-15T18:06:38.653
3@minxomat Whatever, it's just a game. Go on, changed the rules. – MatthewRock – 2015-09-15T18:25:39.543