13
\$\begingroup\$

Write a program in the language of your choosing which when read are the lyrics to a song. It must be a valid program which can be compiled and run without errors. While you could technically print to the screen all the lyrics, you're encouraged to do it with style and avoiding string literals whenever possible.

Given that this is difficult on of itself, you're allowed to write a single section of boilerplate code which doesn't count towards being readable in the lyrics. However, once the block of code begins which must be read as the lyrics to a song, you cannot interrupt it until the song is finished. You can indicate the beginning and end of the song code with comments. Please also specify the lyrics themselves as you would read the code. You can be "liberal" with your interpretation so long as you don't stray too far from what's written, otherwise it will cost you points.

Partial song lyrics are allowed, though you get double points for having the words to an entire song. Judging is divided into 3 categories:

  1. 10 points - Originality
  2. 10 points - Song difficulty
  3. 20 points - Representation of that song in code.

For each submission, I'll give you your score in a comment below. If you edit your answer, just give me a comment indicator and I'll re-evaluate it accordingly. However in order to be fair, each re-evaluation subtracts 2 points from your total score.

An example might be the following:

public class Song {
    public String play() {
        // Song begin
        try {
            if(this instanceof TheRealLife || this instanceof JustFantasy) {
                throw new InALandSlide();
            }
        } catch (InALandSlide e) {
        }
        return "No \"FromReality\"";
        // Song end
    }

    public static void main(String [] args) {
        Song song = new Song();
        song.play();
    }
}

Which gets read:

Is this TheRealLife?
Or is this JustFantasy?
Caught InALandSlide.
No escape \"FromReality\"

Instrumentals aren't allowed, wise guys. ;)

\$\endgroup\$

closed as off-topic by Peter Taylor, ProgramFOX, Doorknob, Ilmari Karonen, Howard Mar 1 '14 at 17:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions without an objective primary winning criterion are off-topic, as they make it impossible to indisputably decide which entry should win." – Peter Taylor, ProgramFOX, Doorknob, Ilmari Karonen, Howard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    \$\begingroup\$ This is an interesting concept, and I'm interested to see the results, but this isn't very objective. How does one determine the 'difficulty' of the song? (etc.) \$\endgroup\$ – Gaffi May 15 '12 at 17:43
  • 3
    \$\begingroup\$ Strongly reminds me of this IOCCC winner \$\endgroup\$ – ugoren May 15 '12 at 20:23
  • \$\begingroup\$ @Gaffi, mostly length, but also the wordiness. Example of a song which would score 0 might be this song is just 6 words long. \$\endgroup\$ – Neil May 16 '12 at 8:11
  • \$\begingroup\$ How about the HQ9 program 9? :P \$\endgroup\$ – Li-aung Yip May 16 '12 at 19:33
  • 1
    \$\begingroup\$ Hint for anyone trying to find a suitable song for coding: "Escape to the Void" seems to be an promising title :) - lyricstime.com/sepultura-escape-to-the-void-lyrics.html \$\endgroup\$ – Cristian Lupascu May 18 '12 at 7:36

10 Answers 10

8
\$\begingroup\$

Python - 8+4+15 = 27 points

Here's on couple of stanzas from The Hunting of the Snark by Lewis Carroll.
It calculates a number, based on the algorithm suggested in the poem, and uses it to state a proof about the voice of the jubjub.

class taking:
    def __init__(self, n): convenient.val = (n)
    def __enter__(self): pass
    def __exit__(self, type, value, traceback): pass
def a(x,y): x.val = y(x.val); return True
class We:
    def __init__(self): self.val=0
    def __add(self, y): return y+sum(self.x)
    def add(self, *x): self.x = x; return self.__add
    def multiply(self,x,by,diminished_by): self.val *= by-diminished_by
    def proceed2divide(self,x,by): self.val /= by
    def subtract(self,x): self.val -= x; return True
perfectly = lambda x: x and not not x
def must_be(x):
    if x: 
        print "\n".join(["Tis the %s of the Jubjub!"%["voice","note","song"][x%3] for x in range(out.val)])
        return out.val
out=convenient=as_you_see=we=then=the=We()
_ = exactly = 15
with\
\
    taking(3) as the_subject_to_reason_about:
    a(convenient, #2 state
    we.add(7,_ & 10)) and then.multiply(out,
    by=1000, diminished_by=8)

    the_result = we.proceed2divide(as_you_see,
    by=992)
    then.subtract(17) and the; answer = must_be(
    exactly and perfectly(True))

The original text:

"Taking Three as the subject to reason about—
A convenient number to state—
We add Seven, and Ten, and then multiply out
By One Thousand diminished by Eight.

"The result we proceed to divide, as you see,
By Nine Hundred and Ninety Two:
Then subtract Seventeen, and the answer must be
Exactly and perfectly true.

\$\endgroup\$
  • \$\begingroup\$ It's nice, I like it. Originality: 8/10, Song difficulty: 4/10, Representation of that song in code: 15/20, making your final score 27. Shame you couldn't use the whole song. \$\endgroup\$ – Neil May 18 '12 at 8:10
  • 2
    \$\begingroup\$ I think the "entire song" criterion has way too much weight. It would have been much easier to pick a one line song. \$\endgroup\$ – ugoren May 18 '12 at 10:20
  • \$\begingroup\$ Given that The Hunting of the Snark is over 500 lines long, that would indeed have been an impressive feat. \$\endgroup\$ – breadbox May 18 '12 at 16:23
  • 1
    \$\begingroup\$ @breadbox, even a single fit would be an impressive feat, the whole thing would be an agony. \$\endgroup\$ – ugoren May 18 '12 at 19:45
6
\$\begingroup\$

Python (8+7+15=30)

Valid Python code synctactically although it does not do anything particulary useful ;-)

from sys import exit as stops ; import os
thing = [] ; me = can = remember = False ; this = open(__file__)
def terrible(v): return v

# ==== start song snippet

me = can = remember = not any(thing)
can = not this.tell(), [True, "dream"]
locals()["deep"] = {"down":{"inside":{"feel_to":"scream"}}}
if `this` + (terrible("silence")): stops(me)

# ===== end song snippet

How it is supposed to be read:

I can't remember anything.
Can't tell if this is true or dream.
Deep down inside I feel to scream.
This terrible silence stops me.
...
(Metallica - One)

\$\endgroup\$
  • \$\begingroup\$ Wow, difficult song choice, but very impressed how you pulled that off. Originality: 8/10, Song difficulty: 7/10, Representation of that song in code: 15/20, making your final score 30. \$\endgroup\$ – Neil May 18 '12 at 8:12
5
\$\begingroup\$

C

Somewhat sloppy, I wrote this in about 15 minutes for giggles. Compiles and runs fine with latest version of G++/MinGW (doesn't really do much, though). You can figure this out just fine by yourself, I think:

class Rick {

public:

    struct us { bool you; bool me; };

    bool giveYouUp()  { return false; }
    bool letYouDown() { return false; }
    bool runAround()  { return false; }
    bool desertYou()  { return false; }
    bool makeYouCry() { return false; }
    bool sayGoodbye() { return false; }
    bool tellALie()   { return false; }
    bool hurtYou()    { return false; }

    bool thinkingOf(bool whatImThinkingOf) { return whatImThinkingOf; }
    bool justWantTo(bool whatIWantToDo) { return whatIWantToDo; }
    bool tellYou(bool whatIWantToTellYou) { return whatIWantToTellYou; }

    void roll() {
        bool gonna = false;
        while (gonna) {
            giveYouUp();
            letYouDown();
            gonna = (runAround() && desertYou());
            makeYouCry();
            sayGoodbye();
            gonna = (tellALie() && hurtYou());
        }

        bool strangersToLove = true;
        us we = {!strangersToLove, !strangersToLove};

        bool knowTheRules = true;
        bool you = knowTheRules, I = knowTheRules;

        bool aFullCommitment = true;
        we.me = thinkingOf(aFullCommitment);

        int me = 0;
        Rick* guys[] = {this, nullptr, nullptr, nullptr, nullptr};

        bool howImFeeling = true;
        we.me = justWantTo(tellYou(howImFeeling));

        bool understand = true;
        while (we.you != understand) {
            we.you = understand;
        }
    }

};

int main() {
    Rick rick;
    rick.roll();

    return 0;
}
\$\endgroup\$
2
\$\begingroup\$

Scala(48 = 2*(7+4+13))

It's Linux! song.

object Song extends App {
  // Compose a song
  trait Compose {
    override def toString = {
      val token = """^.*\$(.*)\$.*$""".r
      val token(verse) = super.toString
      verse.replaceAll("([a-z])([A-Z])", "$1 $2").capitalize
    }
    def excl(ex: String) = println(this + ex)
    def !!(c: Compose) = { excl("."); c }
    def ***(c: Compose) = { excl("..."); c }
    def !(c: Compose) = { excl("!"); c }
    def *(c: Compose) = { excl(","); c }
    def ! = excl("!")
  }
  // It's linux  - lyrics
  case object ItBootsUpFine extends Compose
  case object AllOfTheTime extends Compose
  case object TuxThePenguinIsGreat extends Compose
  case object aPieInTheFace extends Compose
  case object ToTheManIHate extends Compose
  case object EveryoneKnowsItsLinux extends Compose
  case object StableForYouAndMe extends Compose
  case object ItsLinux extends Compose
  case object NoMoreBSODs extends Compose
  case object BetterThanNT extends Compose
  case object BestOfAllItsFree extends Compose
  case object FreeSoftwareForYouAndMe extends Compose
  case object LinuxGPLd extends Compose

  // Singer to sing a song
  def sing(song: => Unit) = { song }

  // Song begins
  sing {
      ItBootsUpFine!
      AllOfTheTime!!
      TuxThePenguinIsGreat!
      aPieInTheFace*
      ToTheManIHate***
      EveryoneKnowsItsLinux!
      ItsLinux!
      ItsLinux!
      StableForYouAndMe!
      ItsLinux!
      ItsLinux!
      NoMoreBSODs!
      ItsLinux!
      ItsLinux!
      BetterThanNT!
      ItsLinux!
      ItsLinux!
      BestOfAllItsFree!
      FreeSoftwareForYouAndMe***
      LinuxGPLd!
  }
  // Song ends
}

Output:

It Boots Up Fine!
All Of The Time.
A Pie In The Face,
Tux The Penguin Is Great!
To The Man IHate...
Everyone Knows Its Linux!
Its Linux!
Its Linux!
Stable For You And Me!
Its Linux!
Its Linux!
No More BSODs!
Its Linux!
Its Linux!
Better Than NT!
Its Linux!
Its Linux!
Best Of All Its Free!
Free Software For You And Me...
Linux GPLd!
\$\endgroup\$
  • \$\begingroup\$ Originality: 7/10, Song difficulty: 4/10, Representation of that song in code: 13/20. Since you put the whole song down, that doubles your score, so that means your final score is 48. Nice one. :) \$\endgroup\$ – Neil May 16 '12 at 8:40
1
\$\begingroup\$

PHP

Tried my favorite song, Stairway to Heaven.

$GLOBALS['sign']= 'words';

class lady extends me // there is a lady
{
  function __construct(){   // who is sure
    global $glitters = 'gold'; // all that glitters is gold
    $buy('stairway_to_heaven'); // and shes buying the stairway to heaven
  }
  $know[] = 'stars are close'; // when she get's there she knows, the stars are close
  function word(){  // with a word she can get
    debug_backtrace(); // what she come for
  }

  $this->buy('stairway_to_heaven'); // and she's buying the stairway to heaven

  $sign = 'words'; // there is a sign on the door
  if(!$sign === $GLOBALS['sign']) // but she want to be sure, cause you know sometimes words have 2 meanings
    exit();

  in_array($tree / $brook, $songbird ? 'sings'); // (literal) in a tree by the brook, there is a songbird who sings

  mysql_real_escape_string($_GET['thoughts']); // sometimes all of our thoughts are misgiven
  for ($i=0;$i<2;i++)
    parent::wonder(); // makes me wonder , makes me wonder

}

How is it read :

There's a lady who's sure all that glitters is gold
And she's buying a stairway to heaven.
When she gets there she knows, if the stars are all close
With a word she can get what she came for.
Ooh, ooh, and she's buying a stairway to heaven.

There's a sign on the wall but she wants to be sure
'Cause you know sometimes words have two meanings.
In a tree by the brook, there's a songbird who sings,
Sometimes all of our thoughts are misgiven.
Ooh, it makes me wonder,
Ooh, it makes me wonder.

\$\endgroup\$
1
\$\begingroup\$

C

Here's a complete song.
You can listen to it in Mama Lisa's World.
Note that the song is included as-is, including the punctuation.

#define breath,
#define smell breath
#define an;}Englishman; main(){printf("%d\n",sizeof
struct x{int
// Song starts here
Fee, fa, fie, fo, fum,
I smell the breath of an Englishman.
// Song ends here
I);}

Prints the number 4.

\$\endgroup\$
1
\$\begingroup\$

Ruby

My take at as close representation as possible. It's easy with Ruby's call chaining.

$lines = []

def thisline n=2
    caller(n).first.match(/:(\d+):/)[1].to_i
end

class Chain < Array
    def method_missing method, *args
        $lines[thisline] = Chain[first, self[1], [method, thisline, args]]
    end

    def -(arg)
        $lines[thisline] = Chain[' - ', thisline, self, arg]
    end

    def tokens
        if size < 3
            if first == :_
                []
            else
                [first.to_s.tr(?_, ?\s).strip]
            end
        elsif size < 4
            [first.to_s.tr(?_, ?\s)] + at(2).tokens
        else
            lhs = case el = at(2)
            when Chain then el.tokens
            when String
                el.empty? ? [?'] : [?', el, ?']
            end

            rhs = case el = at(3)
            when Chain then el.tokens
            when Range then el.first.tokens + ['... '] + el.last.tokens
            end

            lhs + [first.to_s.tr(?_, ?\s)] + rhs
        end
    end
end

def self.method_missing method, *args
    line = thisline(3)

    if args.length > 1
        newlines = args.first.is_a?(String) ? args.first.count(?\n) : 0
        $lines[line] = false
        $lines[line-newlines] = Chain[method, line, Chain[', ', line, *args]]
    else
        $lines[line] = Chain[method, line, *args]
    end
end

####################

The pest in_the eyes of death follows us
Through the dirty streets of blood
It begins to eat inside us, decaying_our_bones
How will we escape_if the void covers our lungs?
We are buried_in the spewed trash_for ourselves

Blood _, pain - nothing_to_say
Why then_- must_we_die?

Escape to the void
Escape to the void

I look at my face on the other side of the mirror
My face falls down_in pieces full of worms
I burst my rotten heart with my own hands
I'm dying and I can',t_help_myself

Blood _, pain - nothing_to_say
Why then_- must_we_die?

What have I been running from?
I'',m_not_guilty
You've shown me the worst way
Cause you',re_my_victim... the_next_one

The pest in_the eyes of death follows us
Through the dirty streets of blood
It begins to eat inside us, decaying_our_bones
How will we escape if_the void covers our lungs?
We are buried in_the spewed trash_for ourselves

Blood _, pain - nothing_to_say
Why then_ - must_we_die?

Escape to the void
Escape to the void

####################

$lines.drop_while {|line| !line }.each_with_index {|line, i|
    puts if line.nil?
    next if not line

    line = line.tokens
    line.map!.with_index {|el, j|
        punct = [', ', ' - ', '... ', ?']

        if line[j-1] == ?' and el == ', '
            ''
        elsif punct.include?(el) or punct.include?(line[j+1])
            el
        else
            el + ?\s
        end
    }

    puts line.join
}

Output

The pest in the eyes of death follows us 
Through the dirty streets of blood 
It begins to eat inside us, decaying our bones 
How will we escape if the void covers our lungs? 
We are buried in the spewed trash for ourselves 

Blood, pain - nothing to say 
Why then - must we die? 

Escape to the void 
Escape to the void 

I look at my face on the other side of the mirror 
My face falls down in pieces full of worms 
I burst my rotten heart with my own hands 
I'm dying and I can't help myself 

Blood, pain - nothing to say 
Why then - must we die? 

What have I been running from? 
I'm not guilty 
You've shown me the worst way
Cause you're my victim... the next one 

The pest in the eyes of death follows us 
Through the dirty streets of blood 
It begins to eat inside us, decaying our bones 
How will we escape if the void covers our lungs? 
We are buried in the spewed trash for ourselves 

Blood, pain - nothing to say 
Why then - must we die? 

Escape to the void 
Escape to the void

To do

  1. Multiline commas (arguments)
  2. Multiline dots (method calls)
\$\endgroup\$
0
\$\begingroup\$

T-SQL Bone Thugs-N-Harmony

DECLARE @line1 varchar(25);
DECLARE @line2 varchar(25);
DECLARE @line4 varchar(25);
DECLARE @line5 varchar(25);

SET @line1 = 'Wake up, wake up, wake up,';
SET @line2 = 'its the';
SET @line4 = 'to get up, get up get up';
SET @line5 = 'so cash your checks and get up';

SELECT @line1 as Layzie, @line2 as Bizzy,
CONVERT(date,DATEADD(day, -
(SELECT
DATEPART(day, GETDATE()) 
- 1), GETDATE())) as FirstOfTheMonth,
@line4 as Layzie, @line5 as Bizzy;

Yeah I know I cheated a bit and I might have the members who sang which line wrong also.

\$\endgroup\$
0
\$\begingroup\$

C - Bottles of Beer

Compile and run this. Lyrics are put into the source code. Compile and execute output to get next line of song. When it says "Time to go...." then compile and execute with the number of bottles specified on the command line, e.g.:

cl prog.c
prog 32 > prog1.c
cl prog1.c
prog1 > .... etc

The code, tested using VS2005:-

// Time to go to the shop and get some beer
//
//
//
//
// #####.#####.#####.#####.#####.#####.#####
// ##.#####.#####.#####.#####.#####.#####.##
// #####.#####.#####.#####.#####.#####.#####
// ##.#####.#####.#####.#####.#####.#####.##

char *z [] = {
"void l(char *s,int b){int i;printf(\"// \");for(i=0;i<b;++i)printf(s);",
"printf(\"\\n\");}\nint main(int argc, char *argv[]){\nint i,j,k,x=%d;",
"char*p;\nif(!x&&argc==2)x=atoi(argv[1]);\nif(!x){printf(\"// Time to ",
"go to the shop and get some beer\\n//\\n//\\n//\\n//\\n\");k=7;\n",
"}else{printf(\"// %%d bottles of beer on the wall, %%d bottles of beer",
".\\n\",x,x);printf(\"// Take one down and pass it round, \");\n",
"if(x>1)printf(\"%%d bottles of beer on the wall.\\n//\\n\",x-1);\n",
"else printf(\"no more bottles of beer on the wall.\\n//\\n\");\n",
"k=x>2?x:2;l(\"  ^   \",x);l(\" / \\\\  \",x);l(\"/   \\\\ \",x);",
"l(\"|   | \",x);l(\"|Duf| \",x);l(\"|   | \",x);l(\"----- \",x);}\n",
"for(i=0;i<4;++i){\nprintf(\"// %%s\", i&1 ? \"##.\" : \"\");\n",
"for(j=i&1;j<k;++j)\nprintf(\"%%s#####\",j!=(i&1)?\".\":\"\");\n",
"printf(\"%%s\\n\",i&1?\".##\":\"\");}\nprintf(\"\\nchar *z [] = {\\n\");\n",
"for(i=0;i<sizeof z/sizeof z[0];++i){\nprintf(\"\\\"\");\n",
"for(p=z[i];*p;++p)\nswitch (*p){\ncase '\\n':printf(\"\\\\n\");break;\n",
"case '\\\\':printf(\"%%c%%c\",92,92);break;\n",
"case '%%':printf(\"%%c\",37);break;\ncase '\"':printf(\"%%c%%c\",92,'\"');break;\n",
"default:printf(\"%%c\", *p);break;}\nprintf(\"\\\",\\n\");}\n",
"printf(\"};\\n\");\nfor(i=0;i<sizeof z/sizeof z[0];++i)\n",
"printf(z[i],x?x-1:0);}\n",
};
void l(char *s,int b){int i;printf("// ");for(i=0;i<b;++i)printf(s);printf("\n");}
int main(int argc, char *argv[]){
int i,j,k,x=0;char*p;
if(!x&&argc==2)x=atoi(argv[1]);
if(!x){printf("// Time to go to the shop and get some beer\n//\n//\n//\n//\n");k=7;
}else{printf("// %d bottles of beer on the wall, %d bottles of beer.\n",x,x);printf("// Take one down and pass it round, ");
if(x>1)printf("%d bottles of beer on the wall.\n//\n",x-1);
else printf("no more bottles of beer on the wall.\n//\n");
k=x>2?x:2;l("  ^   ",x);l(" / \\  ",x);l("/   \\ ",x);l("|   | ",x);l("|Duf| ",x);l("|   | ",x);l("----- ",x);}
for(i=0;i<4;++i){
printf("// %s", i&1 ? "##." : "");
for(j=i&1;j<k;++j)
printf("%s#####",j!=(i&1)?".":"");
printf("%s\n",i&1?".##":"");}
printf("\nchar *z [] = {\n");
for(i=0;i<sizeof z/sizeof z[0];++i){
printf("\"");
for(p=z[i];*p;++p)
switch (*p){
case '\n':printf("\\n");break;
case '\\':printf("%c%c",92,92);break;
case '%':printf("%c",37);break;
case '"':printf("%c%c",92,'"');break;
default:printf("%c", *p);break;}
printf("\",\n");}
printf("};\n");
for(i=0;i<sizeof z/sizeof z[0];++i)
printf(z[i],x?x-1:0);}
\$\endgroup\$
  • 1
    \$\begingroup\$ I make no apologies for my ASCII art! \$\endgroup\$ – Skizz May 18 '12 at 15:33
  • 1
    \$\begingroup\$ Quite impressive, but how does it match the challenge? I thought the idea is that you can read the source as a song. \$\endgroup\$ – ugoren May 18 '12 at 19:47
  • 1
    \$\begingroup\$ @ugoren: Compile and run the executable with a single parameter, the starting number of beers. Then the program outputs the first verse of the song as source code (well, the lyrics in the top comment). Compile the output and run again to get the next verse and so on. \$\endgroup\$ – Skizz May 18 '12 at 21:31
  • \$\begingroup\$ Very nice, but the idea is not a program that prints the song. It's a program that, when its source is read, IS the song. \$\endgroup\$ – ugoren May 19 '12 at 12:35
0
\$\begingroup\$

Perl performs Barnes & Barnes

Ever since I first learned Perl, I've wanted an excuse to use the -P option. Today, that excuse has finally arrived:

#define cry $$
#define people $_
#define some kill
#define we people
#define whenyoudie END
sub yeah{}

# "When You Die", Barnes & Barnes

whenyoudie { you stop drinking beer }
whenyoudie { you stop being here }
whenyoudie { some people,cry }
whenyoudie { we=say "goodbye" }

                yeah

Run it with -M5.010 in addition to the -P option, like so:

$ perl -PM5.010 whenyoudie
goodbye
Hangup
$ 
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.