Codierung im Song - Darstellung von Musiktexten in einer Programmiersprache Ihrer Wahl [geschlossen]

13

Schreiben Sie ein Programm in der Sprache Ihrer Wahl, bei dem es sich beim Lesen um den Liedtext handelt. Es muss ein gültiges Programm sein, das ohne Fehler kompiliert und ausgeführt werden kann. Obwohl Sie alle Texte technisch auf den Bildschirm drucken können, sollten Sie möglichst stilvoll vorgehen und String-Literale vermeiden.

Da dies für sich genommen schwierig ist, dürfen Sie einen einzelnen Abschnitt des Code-Boilerplates schreiben, der nicht dazu zählt, in den Texten lesbar zu sein. Sobald jedoch der Codeblock beginnt, der als Liedtext gelesen werden muss, können Sie ihn nicht unterbrechen, bis das Lied beendet ist. Sie können den Anfang und das Ende des Song-Codes mit Kommentaren angeben. Bitte geben Sie auch die Texte selbst an, als würden Sie den Code lesen. Sie können mit Ihrer Interpretation "liberal" sein, solange Sie nicht zu weit vom Geschriebenen abweichen, sonst kostet es Sie Punkte.

Teilweise Liedtexte sind erlaubt, obwohl Sie doppelte Punkte erhalten, wenn Sie die Wörter zu einem ganzen Lied haben. Das Richten ist in 3 Kategorien unterteilt:

  1. 10 Punkte - Originalität
  2. 10 Punkte - Song Schwierigkeit
  3. 20 Punkte - Darstellung des Songs im Code.

Für jede Einreichung gebe ich Ihnen Ihre Punktzahl in einem Kommentar weiter unten. Wenn Sie Ihre Antwort bearbeiten, geben Sie mir einfach einen Kommentarindikator und ich werde ihn entsprechend neu bewerten. Um jedoch fair zu sein, werden bei jeder Neubewertung 2 Punkte von Ihrer Gesamtpunktzahl abgezogen.

Ein Beispiel könnte folgendes sein:

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();
    }
}

Welches wird gelesen:

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

Instrumentals sind nicht erlaubt, weise Jungs. ;)

Neil
quelle
4
Dies ist ein interessantes Konzept, und ich bin daran interessiert, die Ergebnisse zu sehen, aber das ist nicht sehr objektiv. Wie bestimmt man den Schwierigkeitsgrad des Songs? (etc.)
Gaffi
3
Erinnert
@Gaffi, meistens Länge, aber auch die Worthaftigkeit. Ein Beispiel für ein Lied, das 0 Punkte bringen würde, ist, dass dieses Lied nur 6 Wörter lang ist .
Neil
Wie wäre es mit dem HQ9Programm 9? : P
Li-aung Yip
1
Tipp für alle, die nach einem geeigneten Song zum Codieren suchen: "Escape to the Void" scheint ein vielversprechender Titel zu sein :) - lyricstime.com/sepultura-escape-to-the-void-lyrics.html
Cristian Lupascu

Antworten:

8

Python - 8 + 4 + 15 = 27 Punkte

Hier sind einige Strophen aus The Hunting of the Snark von Lewis Carroll.
Es berechnet eine Zahl auf der Grundlage des im Gedicht vorgeschlagenen Algorithmus und verwendet sie, um einen Beweis für die Stimme des Jubjubs zu liefern.

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))

Der ursprüngliche Text:

"Nehmen Sie Drei als das Thema der Vernunft über -
Eine bequeme Zahl,
um anzugeben - Wir addieren Sieben und Zehn, und multiplizieren Sie dann
mit Tausend, vermindert um Acht.

"Das Ergebnis teilen wir, wie Sie sehen,
durch neunhundertzweiundneunzig:
Dann subtrahieren Sie siebzehn, und die Antwort muss
genau und vollkommen wahr sein.

ugoren
quelle
Es ist schön, ich mag es. Originality: 8/10, Song difficulty: 4/10, Representation of that song in code: 15/20, Machen Ihre Endnote 27. Shame Sie konnte nicht das ganze Lied verwenden.
Neil
2
Ich denke, das Kriterium "Gesamtes Lied" hat viel zu viel Gewicht. Es wäre viel einfacher gewesen, einen einzeiligen Song auszuwählen.
Ugoren
Angesichts der Länge von mehr als 500 Zeilen bei The Hunting of the Snark wäre dies eine beeindruckende Leistung gewesen.
Brotkasten
1
@breadbox, schon ein einziger Anfall wäre eine beeindruckende Leistung, das Ganze wäre eine Qual.
Ugoren
6

Python (8 + 7 + 15 = 30)

Gültiger Python-Code synchron, obwohl er nichts besonders Nützliches bewirkt ;-)

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

Wie soll es gelesen werden:

Ich kann mich an nichts erinnern.
Kann nicht sagen, ob dies wahr ist oder träumt.
Tief im Inneren habe ich das Gefühl zu schreien.
Diese schreckliche Stille hält mich auf.
...
(Metallica - Eins)

ChristopheD
quelle
Wow, schwierige Songauswahl, aber sehr beeindruckt, wie du das geschafft hast. Originality: 8/10, Song difficulty: 7/10, Representation of that song in code: 15/20, Macht Ihr Endnote 30.
Neil
5

C

Etwas schlampig schrieb ich das in ca. 15 Minuten wegen Kicherns. Kompiliert und läuft gut mit der neuesten Version von G ++ / MinGW (macht aber nicht wirklich viel). Du kannst das ganz gut selbst herausfinden, denke ich:

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;
}
Stuntddude
quelle
2

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

Es ist Linux! Lied.

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
}

Ausgabe:

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!
Prinz John Wesley
quelle
Originality: 7/10, Song difficulty: 4/10, Representation of that song in code: 13/20. Da Sie das ganze Lied auf den Tisch legen, verdoppelt sich Ihre Punktzahl, was bedeutet, dass Ihre endgültige Punktzahl 48 ist. :)
Neil
1

PHP

Versuchte mein Lieblingslied, 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

}

Wie ist es zu lesen:

Es gibt eine Frau, die sicher ist, dass alles, was glänzt, Gold ist.
Und sie kauft eine Treppe zum Himmel.
Als sie dort ankommt, weiß sie, ob die Sterne alle nah sind.
Mit einem Wort kann sie bekommen, wofür sie gekommen ist.
Oh, oh, und sie kauft eine Treppe zum Himmel.

Es gibt ein Schild an der Wand, aber sie möchte sicher sein
, weil man weiß, dass Wörter manchmal zwei Bedeutungen haben.
In einem Baum am Bach singt ein Singvogel.
Manchmal sind alle unsere Gedanken falsch.
Oh, ich wundere mich,
oh, ich wundere mich.

Karthik
quelle
1

C

Hier ist ein komplettes Lied.
Sie können es in Mama Lisas Welt hören .
Beachten Sie, dass das Lied wie es ist enthalten ist, einschließlich der Zeichensetzung.

#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);}

Druckt die Nummer 4.

ugoren
quelle
1

Rubin

Meine Darstellung so nah wie möglich. Mit Rubys Anrufverkettung ist das ganz einfach.

$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
}

Ausgabe

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

Machen

  1. Mehrzeilige Kommas (Argumente)
  2. Mehrzeilige Punkte (Methodenaufrufe)
cabron
quelle
0

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;

Ja, ich weiß, ich habe ein bisschen geschummelt und ich könnte die Mitglieder haben, die die falsche Zeile sangen.

Stephen
quelle
0

C - Flaschen Bier

Kompilieren Sie das und führen Sie es aus. Songtexte werden in den Quellcode eingefügt. Kompiliere und führe die Ausgabe aus, um die nächste Zeile des Songs zu erhalten. Wenn "Time to go ...." angezeigt wird, kompilieren Sie die Datei und führen Sie sie mit der in der Befehlszeile angegebenen Anzahl von Flaschen aus. Beispiel:

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

Der Code, getestet mit 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);}
Skizz
quelle
1
Ich entschuldige mich nicht für meine ASCII-Kunst!
Skizz
1
Ziemlich beeindruckend, aber wie passt es zur Herausforderung? Ich dachte, die Idee ist, dass man die Quelle als Lied lesen kann.
Ugoren
1
@ugoren: Kompiliere und starte die ausführbare Datei mit einem einzigen Parameter, der Startanzahl der Biere. Dann gibt das Programm den ersten Vers des Songs als Quellcode aus (also die Texte im oberen Kommentar). Kompilieren Sie die Ausgabe und führen Sie sie erneut aus, um den nächsten Vers usw. zu erhalten.
Skizz
Sehr schön, aber die Idee ist kein Programm, das das Lied druckt. Es ist ein Programm, das, wenn seine Quelle gelesen wird, das Lied IST.
Ugoren
0

Perl spielt Barnes & Barnes

Seit ich Perl lernte, wollte ich eine Ausrede, um diese -POption zu nutzen . Heute ist diese Ausrede endlich da:

#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

Führen Sie es -M5.010zusätzlich zu der -POption wie folgt aus:

$ perl -PM5.010 whenyoudie
goodbye
Hangup
$ 
Brot-Box
quelle