首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用您所选择的编程语言编写歌曲表示音乐歌词的代码。

用您所选择的编程语言编写歌曲表示音乐歌词的代码。
EN

Code Golf用户
提问于 2012-05-15 11:37:24
回答 6查看 18K关注 0票数 13

用你选择的语言编写一个程序,当你读到它时,它就是一首歌的歌词。它必须是一个有效的程序,可以编译和运行,没有错误。虽然你可以从技术上将所有歌词打印到屏幕上,但我们鼓励你尽可能地使用风格和避免字符串文字。

考虑到这本身是很困难的,你可以写一段样板代码,这不包括歌词中的可读性。但是,一旦代码块开始,必须作为歌曲的歌词读取,在歌曲完成之前,您不能中断它。您可以用注释指示歌曲代码的开头和结尾。也请指定歌词本身,因为你会读的代码。你可以用你的解释“自由”,只要你不偏离写的太远,否则它将花费你的分数。

部分歌词是允许的,虽然你得到了双分的话,一整首歌。裁判分为三大类:

  1. 10分-原创
  2. 10分-歌曲难度
  3. 20分-用代码表示这首歌。

对于每一份意见书,我将在下面的评论中给出你的分数。如果你编辑你的答案,只要给我一个评论指标,我会重新评估它相应。然而,为了公平起见,每一次重新评估都会从你的总分中减去2分.

例如,可以如下所示:

代码语言:javascript
运行
复制
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();
    }
}

它被读到:

代码语言:javascript
运行
复制
Is this TheRealLife?
Or is this JustFantasy?
Caught InALandSlide.
No escape \"FromReality\"

乐器是不允许的,聪明人。;)

EN

回答 6

Code Golf用户

发布于 2012-05-17 13:29:50

Python - 8+4+15 =27分

这里是刘易斯·卡罗尔的“猎杀咆哮者”中的几节。

它根据诗中所建议的算法计算一个数字,并用它来证明朱布朱布的声音。

代码语言:javascript
运行
复制
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))

原文如下:

“以3作为主语-- --一个方便的数字-- 我们加了7和10,然后把out乘以1,000被Eight.减了”我们的结果是,如你所看到的,除以992:然后减去17,答案必须精确和完美地be true.。

票数 8
EN

Code Golf用户

发布于 2012-05-17 21:03:50

Python (8+7+15=30)

有效的Python代码语法上虽然它没有做任何特别有用的事情;-)

代码语言:javascript
运行
复制
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

应如何阅读:

我什么都不记得了。说不出这是真的,或者我内心深处的dream.感觉到了scream.,这种可怕的沉默阻止了me. ... (Metallica - One)

票数 6
EN

Code Golf用户

发布于 2014-02-28 05:17:42

C

有点草率,我写了大约15分钟的笑声。在最新版本的G++/MinGW中编译和运行都很好(但实际做的并不多)。你自己就能解决这个问题,我想:

代码语言:javascript
运行
复制
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;
}
票数 5
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/5836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档