Put the line in the code you nut and shake it all up

Using one programming language write 5 single-line programs, each of which outputs a different line of the first verse to Harry Nilsson's 1972 song "Coconut" when run individually:

Brother bought a coconut, he bought it for a dime
His sister had another one, she paid it for a lime
She put the lime in the coconut, she drank them both up
She put the lime in the coconut, she drank them both up
She put the lime in the coconut, she drank them both up

The last 3 lines have the same lyrics, so your last 3 programs might be as well.

There are 5 factorial or 120 ways these 5 single-line programs can be arranged one per line in a single 5-line program. You must optimize your single-line programs such that for as many of these 120 combinations as possible the 5-line program outputs the entire verse in its proper order, exactly as it appears above.

Example

The simplest answer would have 5 single line print statements, the last 3 identical:

print('Brother bought a coconut, he bought it for a dime')
print('His sister had another one, she paid it for a lime')
print('She put the lime in the coconut, she drank them both up')
print('She put the lime in the coconut, she drank them both up')
print('She put the lime in the coconut, she drank them both up')

The output to the 5-line programs will be the verse in its proper order as long as the first two single-liners are in their correct places. Only 6 of the 120 possible arrangements accomplish this.

Scoring

The submission with the most working cases out of all 120 wins. Tie breaker goes to the set of programs with the lowest cumulative byte count (newlines not counted). The example has 309 bytes.

Details

• Your programs may not read their own source code. Nor should they read other external files or require a network connection.

• Output to stdout or closest alternative. You may also output to a file with the name of your choice.

• "Single-line programs" are strings that contain any characters except line terminators (you'll probably just need to worry about newlines) .

• When composing the single-liners into the 5-liners you should add exactly 4 newlines, one between each adjacent pair of single-liners. You may optionally add a trailing newline.

• "Write 5 programs which each output a different line..." isn't that impossible? – feersum Jan 24 '15 at 0:44
• @feersum The lines are different. Three of them just happen to have the same text. – Calvin's Hobbies Jan 24 '15 at 0:54
• What if I have a Java file containing 5 classes, each with a main method? Then which should be run, when running the program? – feersum Jan 24 '15 at 1:13
• @feersum Well what does your compiler do? I'm not sure what Java does when multiple classes in the same file both have main. – Calvin's Hobbies Jan 24 '15 at 1:36
• The way I remember this one is that one Coca-Cola ad where they "put the lime in the Coke"... – Joe Z. Feb 6 '15 at 19:57

CJam, 120 valid permutations, 334 299 290 bytes

"She put the lime in the coconut, she drank them both up"N+
"Brother bought a coconut, he bought it for a dime"N+]$~ "She put the lime in the coconut, she drank them both up"N+ "His sister had another one, she paid it for a lime"N+]$~
"She put the lime in the coconut, she drank them both up"N+


Pretty simple logic:

• Put each line of the song in each of the 5 programs
• Wrap everything on stack in an array
• Sort the array
• Unwrap the array so that the next program can use the same logic
• In each step, we have the partial lyrics in an array. Luckily, sorting the array gives the correct order of the lyrics.

UPDATE: Turns out that you don't need the wrap-sort-unwrap cycle after the 3 similar and appearing at the end lines of the song. I can explain why if its not that apparent :)

Prelude, 120 permutations, 2045 2035 bytes

9-9-9-9-9-9-9-9-9-5-97+993++09-9-9-9-9-9-9-1-8992++96+209-9-9-9-9-9-9-1-94+58992++09-9-9-9-9-9-9-1-92+95+199+409-9-9-9-9-9-9-1-58991++09-9-9-9-9-9-9-1-09-9-9-9-9-7-992++993++95+96+396+309-9-9-9-9-9-9-1-58992++09-9-9-9-9-9-9-1-95+909-9-9-9-9-9-9-1-594+993+09-9-9-9-9-9-9-1-58992++09-9-9-9-9-9-9-1-992++993++97+09-9-9-9-9-9-9-1-5809-4-                                                                          (9+9+9+9+9+9+9+9+9+9+6+!)
9-9-9-9-9-9-9-9-9-5-594+9409-9-9-9-9-9-9-1-109-9-9-9-9-9-9-1-99+96+609-9-9-9-9-9-9-1-992++909-9-9-9-9-9-9-1-992++87993++96+209-9-9-9-9-9-9-1-5809-9-9-9-9-9-9-1-09-9-9-9-9-7-992++993++95+96+396+309-9-9-9-9-9-9-1-109-9-9-9-9-9-9-1-992++87993++96+209-9-9-9-9-9-9-1-99+58992++96+99+09-9-9-3-                                             (9+9+9+9+9+9+9+9+9+9+6+!)
9-9-9-9-9-9-9-9-9-5-97+993++09-9-9-9-9-9-9-1-8992++96+209-9-9-9-9-9-9-1-94+58992++09-9-9-9-9-9-9-1-92+95+199+409-9-9-9-9-9-9-1-58991++09-9-9-9-9-9-9-1-09-9-9-9-9-7-992++993++95+96+396+309-9-9-9-9-9-9-1-58992++09-9-9-9-9-9-9-1-95+909-9-9-9-9-9-9-1-594+993+09-9-9-9-9-9-9-1-58992++09-9-9-9-9-9-9-1-992++993++97+09-9-9-9-9-9-9-1-5809-4-                                                 (9+9+9+9+9+9+9+9+9+9+6+!)
9-9-9-9-9-9-9-9-9-5-594+993+09-9-9-9-9-9-9-1-109-9-9-9-9-9-9-1-99+96+609-9-9-9-9-9-9-1-992++909-9-9-9-9-9-9-1-49197+09-9-9-9-9-9-9-1-58991++09-9-9-9-9-9-9-1-09-9-9-9-9-7-595+96+09-9-9-9-9-9-9-1-99+58992++96+95+109-9-9-9-9-9-9-1-41809-9-9-9-9-9-9-1-99+5992++991++9991++09-9-9-9-9-9-9-1-991++909-9-6-                                                           (9+9+9+9+9+9+9+9+9+9+6+!)
9-9-9-9-9-9-9-9-9-5-97+993++09-9-9-9-9-9-9-1-8992++96+209-9-9-9-9-9-9-1-94+58992++09-9-9-9-9-9-9-1-92+95+199+409-9-9-9-9-9-9-1-58991++09-9-9-9-9-9-9-1-09-9-9-9-9-7-992++993++95+96+396+309-9-9-9-9-9-9-1-58992++09-9-9-9-9-9-9-1-95+909-9-9-9-9-9-9-1-594+993+09-9-9-9-9-9-9-1-58992++09-9-9-9-9-9-9-1-992++993++97+09-9-9-9-9-9-9-1-5809-4-                                                                                                   (9+9+9+9+9+9+9+9+9+9+6+!)


This has ultimately convinced me that Prelude and CJam need a child. If it wasn't for Prelude's very limited instruction set, this submission would actually be very competitive, if it wouldn't even beat CJam.

The basic idea is the following

"push line 4"               print
"push line 1"print
"push line 3"          print
"push line 2"     print
"push line 5"                    print


In Prelude, each line is its own "voice" with its own stack, and these voices are executed in parallel. That is, in the full program, each line will just individually construct the string and at print it at the end. But due to the offsets of the print statements, the order of the lines doesn't matter at all for the order of the output, since execution is left-to-right, not top-to-bottom.

Now, why are the lines so long? Prelude only stores numbers on its stack. Furthermore, it can only push a single-digit number at a time, so larger numbers have to be constructed from addition and subtraction (there is no multiplication either or other arithmetic either). So the largest part of code is simply calculating and pushing the right character codes. To shorten this a bit, I offset them by 96. At the end, to print, I loop until the stack is empty (i.e. a 0 is encountered), add 96 to each number, and print it.

Note that the strings are pushed in reverse, since they're printed from last to first character.

This assumes the Python interpreter with NUMERIC_OUTPUT = False (which is how the spec defines I/O).

I used the following CJam code to generate the string construction:

"Brother bought a coconut, he bought it for a dime
"W%{i96-_0<{zLa*9/:,'-*'-+0\+}{La*9/:,_,'+*W<}?}%


Lastly, just for fun, why I think this would be really short if Prelude had a concept of strings:

"pu htob meht knard ehs ,tunococ eht ni emil eht tup ehS"N+!
"emid a rof ti thguob eh ,tunococ a thguob rehtorB"N+!
"pu htob meht knard ehs ,tunococ eht ni emil eht tup ehS"N+!
"emil a rof ti diap ehs ,eno rehtona dah retsis siH"N+!
"pu htob meht knard ehs ,tunococ eht ni emil eht tup ehS"N+!


Now the print statements ! are already in the right order, so I wouldn't even need to offset them. I think I'll get down to implementing this some time.

Ruby, 120 valid permutations, 430 bytes

$*[1]='His sister had another one, she paid it for a lime';a||=at_exit{puts($*-[p])}
$*[0]='Brother bought a coconut, he bought it for a dime';a||=at_exit{puts($*)}
$*[2]='She put the lime in the coconut, she drank them both up';a||=at_exit{puts($*-[p])}
$*[3]='She put the lime in the coconut, she drank them both up';a||=at_exit{puts($*-[p])}
$*[4]='She put the lime in the coconut, she drank them both up';a||=at_exit{puts($*-[p])}


Works in any order, or individually. Each line modifies global state, then sets a hook to be executed at the end of the program unless the hook has already been set.

• The question says " 5 single-line programs". Does not this mean each line should be in a separate program? Not all in one? – bacchusbeale Jan 24 '15 at 10:30
• Just a question of formatting. Each line works as its own program. – histocrat Jan 24 '15 at 13:36

><>, 120 permutations, 703 bytes

<    /a"emid a rof ti thguob eh ,tunococ a thguob rehtorB"0a.#.!50padpacpabpaapa9pa8pa7p97p87p77p67p57p95p84p73p62p51"/////\\\\\>l0=?;o"
<   / a"emil a rof ti diap ehs ,eno rehtona dah retsis siH"09.#.!50padpacpabpaapa9pa8pa7p97p87p77p67p57p95p84p73p62p51"/////\\\\\>l0=?;o"
<  /  a"pu htob meht knard ehs ,tunococ eht ni emil eht tup ehS"08.#.!50padpacpabpaapa9pa8pa7p97p87p77p67p57p95p84p73p62p51"/////\\\\\>l0=?;o"
< /   a"pu htob meht knard ehs ,tunococ eht ni emil eht tup ehS"07.#.!50padpacpabpaapa9pa8pa7p97p87p77p67p57p95p84p73p62p51"/////\\\\\>l0=?;o"
</    a"pu htob meht knard ehs ,tunococ eht ni emil eht tup ehS"06.#.!50padpacpabpaapa9pa8pa7p97p87p77p67p57p95p84p73p62p51"/////\\\\\>l0=?;o"


The one-liner restriction was pretty tough for a 2D language, so I had to find a way to make the most of the . teleport instruction.

The initial < makes program flow leftward, wrapping around and executing

"o;?=0l>\\\\\\/////"15p26p37p48p59p75p76p77p78p79p7ap8ap9apaapbapcapdap


This is a series of p (put) instructions which places chars until the board looks like this:

<    /<lyrics1>0a.#.!50<blah>
<   / <lyrics2>09.#.!50<blah>
<  /  <lyrics3>08.#.!50<blah>
< /   <lyrics4>07.#.!50<blah>
</    <lyrics5>06.#.!50<blah>
/     \
/    \
/   \
/  \
/ \
>l0=?;o


The #.!50 then flips program flow back to rightward again, before jumping to line 5. What follows is this:

• Following the / mirror on line 5 finds lyrics 5, which is pushed onto the stack. We then teleport to line 6.
• Following the / mirror on line 6 finds lyrics 4, which is pushed onto the stack. We then teleport to line 7.
• Following the / mirror on line 7 finds lyrics 3...

This happens until we push lyrics 1, at which point we teleport to line 10. This is a loop to print the whole stack until it is empty.

If only one line of the program is present, then the \ mirrors do the same job as the teleports on each lyric line.

If the program is scrambled, then the explanation above still applies, so the program works for all permutations!

JavaScript (V8), 389 bytes

a=setTimeout;a(_=>a(_=>printShe put the lime in the coconut, she drank them both up))
a=setTimeout;a(_=>a(_=>printShe put the lime in the coconut, she drank them both up))
a=setTimeout;a(_=>a(_=>printShe put the lime in the coconut, she drank them both up))
setTimeout(_=>printHis sister had another one, she paid it for a lime)
printBrother bought a coconut, he bought it for a dime


Try it online!

Silly

Deadfish~, 6 (it's probably not possible to do more)

{iiiiii}iiiiiic{iiiii}ddcdddciiiiic{d}ddcdddc{i}iiic{{d}ii}ddc{iiiiii}iiiiiic{i}iiiciiiiiic{d}ddddcic{i}iic{{d}ii}ddddc{iiiiii}iiiiic{dddddd}dddddc{{i}ddd}dddc{i}iic{d}ddc{i}iicdc{i}dddcdc{{d}iii}ddc{d}ddc{{i}ddd}iicdddc{{d}iii}ic{iiiiii}iiiiiic{i}iiiciiiiiic{d}ddddcic{i}iic{{d}ii}ddddc{{i}ddd}iiic{i}ic{{d}ii}ddddc{{i}ddd}c{i}dciiic{{d}ii}ddc{iiiiii}iiiiic{dddddd}dddddc{{i}ddd}ddciiiiiciiiic{d}iic

{iii}iic{iiii}c{iii}iiic{i}c{{d}ii}dddc{{i}dd}iiic{d}c{i}cic{d}dddddc{i}iiic{{d}ii}ddc{{i}ddd}iic{d}iiiciiic{{d}iii}iic{iiiiii}iiiiic{i}iiiciciiiiic{d}ddcdddc{i}iiic{{d}ii}ddc{{i}dd}dcdc{d}ic{dddddd}iiic{d}ddc{{i}dd}iiic{d}dcdddc{{d}iii}ic{{i}dd}c{d}dddddc{i}ddcdddddc{{d}iii}iic{{i}ddd}iiic{i}ic{{d}ii}ddddc{{i}ddd}c{i}dciiic{{d}ii}ddc{iiiiii}iiiiic{dddddd}dddddc{{i}ddd}iiiiiicdddciiiic{d}iic

{iii}iic{iiiii}ic{ii}icdddc{{d}iii}ic{{i}dd}ciiiiicdc{{d}ii}ddddc{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiiiiicdddciiiic{d}iic{{d}iii}ic{{i}ddd}iiiciiiiic{{d}ii}iic{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}dddc{i}iic{d}ddc{i}iicdc{i}dddcdc{{d}iii}ddc{d}ddc{{i}dd}iiic{d}dcdddc{{d}iii}ic{{i}ddd}ddc{i}iiiic{dd}iiic{i}iiicdddc{{d}iii}dddddc{{i}dd}iiiic{d}ddcdddc{i}ddc{{d}ii}iiic{iiiiii}iiiiiic{i}iiiciiiiic{d}ddc{{d}iii}ddc{{i}dd}iiiiicdddddc

{iii}iic{iiiii}ic{ii}icdddc{{d}iii}ic{{i}dd}ciiiiicdc{{d}ii}ddddc{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiiiiicdddciiiic{d}iic{{d}iii}ic{{i}ddd}iiiciiiiic{{d}ii}iic{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}dddc{i}iic{d}ddc{i}iicdc{i}dddcdc{{d}iii}ddc{d}ddc{{i}dd}iiic{d}dcdddc{{d}iii}ic{{i}ddd}ddc{i}iiiic{dd}iiic{i}iiicdddc{{d}iii}dddddc{{i}dd}iiiic{d}ddcdddc{i}ddc{{d}ii}iiic{iiiiii}iiiiiic{i}iiiciiiiic{d}ddc{{d}iii}ddc{{i}dd}iiiiicdddddc

{iii}iic{iiiii}ic{ii}icdddc{{d}iii}ic{{i}dd}ciiiiicdc{{d}ii}ddddc{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}iiiiiicdddciiiic{d}iic{{d}iii}ic{{i}ddd}iiiciiiiic{{d}ii}iic{{i}dd}iiiic{d}ddcdddc{{d}iii}ic{{i}ddd}dddc{i}iic{d}ddc{i}iicdc{i}dddcdc{{d}iii}ddc{d}ddc{{i}dd}iiic{d}dcdddc{{d}iii}ic{{i}ddd}ddc{i}iiiic{dd}iiic{i}iiicdddc{{d}iii}dddddc{{i}dd}iiiic{d}ddcdddc{i}ddc{{d}ii}iiic{iiiiii}iiiiiic{i}iiiciiiiic{d}ddc{{d}iii}ddc{{i}dd}iiiiicdddddc


This is so long.....

• Please read the challenge again, this is not a plain kolmogorov-complexity task – Leo Apr 1 at 5:23
• @Leo It's hard to tell whether it's actually pure kolmogorov-complexity. In this case I can fix the answer. With the other one, I got mixed up. – A username Apr 1 at 5:32
• Are you using any kind of generator? – wasif Apr 1 at 5:36
• Do you think I write these by hand? I did write the generator though... – A username Apr 1 at 5:37
• Crazy, generated programs are too long, I am planning to write an optimal generator. You don't know that s can push the accumulator squared, so you can save a lot of bytes..... – wasif Apr 1 at 5:40