歌曲编码-用您选择的编程语言表示音乐歌词[关闭]


13

用您选择的语言编写一个程序,当您阅读该程序时,便是歌曲的歌词。它必须是有效的程序,可以被编译和运行且没有错误。从技术上讲,您可以在屏幕上打印所有歌词,但建议您使用样式,并尽可能避免使用字符串文字。

鉴于这本身就很困难,因此您可以编写一段样板代码,而这部分代码并不构成歌词可读性。但是,一旦开始读取必须作为歌曲歌词的代码块,您就无法在歌曲完成之前中断它。您可以用注释指示歌曲代码的开头和结尾。请同时指定歌词本身,就像阅读代码一样。只要您与所写内容的相距不远,您就可以对自己的解释“持开放态度”,否则将花费您宝贵的时间。

允许使用部分歌曲的歌词,尽管将整首歌中的单词包含在其中会获得双倍积分。评审分为3类:

  1. 10分-创意
  2. 10分-歌曲难度
  3. 20分-该歌曲在代码中的表示形式。

对于每次提交,我都会在下面的评论中给您您的分数。如果您编辑答案,请给我一个注释指示符,然后我将对其进行重新评估。但是,为了公平起见,每次重新评估都会从您的总得分中减去2分。

示例如下:

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

读取内容:

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

智者,不允许演奏乐器。;)


4
这是一个有趣的概念,我很想看到结果,但这不是很客观。如何确定歌曲的“难度”?(等)
加菲2012年

3
强烈使我想起了这位IOCCC冠军
ugoren 2012年

@Gaffi,主要是长度,但也很冗长。例如,这首歌的得分为0,可能只有6个字长
尼尔2012年

怎么样的HQ9程序9?:P
叶丽昂

1
对任何试图找到合适的歌曲进行编码的提示:“逃离虚空”似乎是一个很有前途的标题:)- lyricss.time
com / sepultura

Answers:


8

Python-8 + 4 + 15 = 27分

这是刘易斯·卡罗尔(Lewis Carroll)的《蛇狩猎》中的几个节。
它根据这首诗中建议的算法计算一个数字,并用它来陈述有关枣树声音的证据。

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

原文:

“以三为理由-
一个方便的数字-
我们将七和十相加,然后乘以
一千减去八。

“如您所见,我们继续将结果除以
九百和九十二:
然后减去十七,答案必须
完全正确。


很好,我喜欢。 Originality: 8/10Song difficulty: 4/10Representation of that song in code: 15/20,使你的最后得分27羞耻你不能使用全曲。
尼尔2012年

2
我认为“整首歌”标准的重要性太大。选择一首单行歌曲会容易得多。
ugoren

鉴于《捕蛇人》的长度超过500行,这确实是一个了不起的壮举。
面包箱

1
@breadbox,即使一次安装也将是一个令人印象深刻的壮举,整件事将是一个痛苦。
ugoren

6

巨蟒(8 + 7 + 15 = 30)

尽管并没有做任何特别有用的操作,但还是可以有效地同步处理Python代码;-)

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

应该如何阅读:

我什么都不记得了
无法判断这是真的还是梦想。
我内心深处尖叫。
这种可怕的沉默阻止了我。
...
(Metallica-一)


哇,歌曲选择困难,但是您如何实现这一目标给人留下了深刻的印象。 Originality: 8/10Song difficulty: 7/10Representation of that song in code: 15/20,让您的最终得分30
尼尔

5

C

有点草率,我在大约15分钟内写了些笑声。可以使用最新版本的G ++ / MinGW编译并正常运行(不过,实际上并没有做太多事情)。我想,您可以自己弄清楚这一点:

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

2

斯卡拉(48 = 2 *(7 + 4 + 13))

它是Linux!歌曲。

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
}

输出:

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!

Originality: 7/10Song difficulty: 4/10Representation of that song in code: 13/20。由于您放下了整首歌曲,因此您的得分翻了一番,因此最终得分为48。不错。:)
尼尔2012年

1

的PHP

试过我最喜欢的歌曲《通往天堂的阶梯》。

$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

}

怎么读:

有一位女士肯定所有闪闪发光的都是黄金,
并且她正在购买通往天堂的阶梯。
当她到达那里时,她知道,如果星星都近在咫尺,
她就能得到她想要的东西。
哦,哦,她正在买通往天堂的楼梯。

墙上有一个标牌,但她想确保
,因为您知道有时候单词有两种含义。
在小溪旁的一棵树上,有只鸣禽在唱歌,
有时我们的所有想法都令人作呕。
哦,这让我感到奇怪,
哦,这让我感到好奇。


1

C

这是一首完整的歌。
您可以在《丽莎妈妈的世界》中收听。
请注意,歌曲原样包含标点符号。

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

打印数字4。


1

红宝石

我尽可能地代表。使用Ruby的调用链接很容易。

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

输出量

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

去做

  1. 多行逗号(参数)
  2. 多行点(方法调用)

0

T-SQL骨头暴徒-N和谐

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;

是的,我知道我有点作弊,而且我的成员可能也唱错了哪条线。


0

C-啤酒瓶

编译并运行它。歌词被放入源代码中。编译并执行输出以获取歌曲的下一行。当它显示“该走了……”时,然后使用命令行上指定的瓶子数进行编译和执行,例如:

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

使用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);}

1
我不对我的ASCII艺术表示歉意!
Skizz

1
令人印象深刻,但它如何应对挑战?我以为您可以将源代码作为歌曲阅读。
ugoren

1
@ugoren:使用单个参数(啤酒的起始数量)编译并运行可执行文件。然后,程序将歌曲的第一节经文作为源代码输出(当然,顶部注释中的歌词)。编译输出,然后再次运行以获取下一节,依此类推。
Skizz

很好,但是这个主意不是打印歌曲的程序。这是一个程序,当其来源被读取时,就是歌曲。
ugoren

0

Perl表演Barnes&Barnes

自从我第一次学习Perl以来,我一直想要一个借口使用该-P选项。今天,这个借口终于到了:

#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

-M5.010-P选项外,还可以使用来运行它,如下所示:

$ perl -PM5.010 whenyoudie
goodbye
Hangup
$ 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.