“Hello World”上的代码保龄球?
与流行的代码高尔夫挑战相反,这里展示了许多常客的天才,我希望看到这种天才以相反的方式得到体现。
挑战是成功执行“Hello World”,特别关注过于复杂的问题。不是冗长,不是晦涩,只是纯粹的草率/过于复杂。
将The Daily WTF视为灵感。
function mb2($o){return (int)($o*2);}
$alphabet = str_split("abcdefghijklmnopqrstuvwxyz");
$alphabet[] = " ";
$output = "";
for ($i = 0; $i <= 10; $i++)
switch (mb2($i*.5)) {
case 0: $output = $output . $alphabet[07]; break;
case 1: $output = $output . $alphabet[04]; break;
case 2: $output = $output . $alphabet[11]; break;
case 3: $output = $output . $alphabet[11]; break;
case 4: $output = $output . $alphabet[14]; break;
case 5: $output = $output . array_pop($alphabet); break;
case 6: $output = $output . $alphabet[22]; break;
case 7: $output = $output . $alphabet[14]; break;
case 8: $output = $output . $alphabet[17]; break;
case 9: $output = $output . $alphabet[11]; break;
case 10: $output = $output . $alphabet[03]; break;
}
print $output; // hello world
Contrary to the popular code-golf challenges which demonstrate the genius of many regulars here, I'd like to see that genius illustrated in an antithetical fashion.
The challenge is to successfully perform "Hello World" with special focus on over-complicating matters. Not verbosity, not obscurity, just pure sloppiness/over-complication.
Think of The Daily WTF as inspiration.
function mb2($o){return (int)($o*2);}
$alphabet = str_split("abcdefghijklmnopqrstuvwxyz");
$alphabet[] = " ";
$output = "";
for ($i = 0; $i <= 10; $i++)
switch (mb2($i*.5)) {
case 0: $output = $output . $alphabet[07]; break;
case 1: $output = $output . $alphabet[04]; break;
case 2: $output = $output . $alphabet[11]; break;
case 3: $output = $output . $alphabet[11]; break;
case 4: $output = $output . $alphabet[14]; break;
case 5: $output = $output . array_pop($alphabet); break;
case 6: $output = $output . $alphabet[22]; break;
case 7: $output = $output . $alphabet[14]; break;
case 8: $output = $output . $alphabet[17]; break;
case 9: $output = $output . $alphabet[11]; break;
case 10: $output = $output . $alphabet[03]; break;
}
print $output; // hello world
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
你自找的。 Python:
You asked for it. Python:
有人可以帮助我加快我的程序吗? Python 即使只运行一行也太慢了!
Can someone help me speed up my program. Python is so slow even to run just one line!
我认为很难击败 GNU "Hello World" (查看 tar 即可享受它的全部荣耀,包括测试、makefile(s!)、man 等):
I think it's pretty hard to beat the GNU "Hello World" (view the tar to enjoy it in its full glory, including tests, makefile(s!), man, etc.):
我很偏执。我不信任编译器。我必须告诉它如何完成它的工作 (C#):
。
I'm paranoid. I don't trust the compiler. I have to tell it how to do its job (C#):
.
找到适合工作的语言始终是一个问题。脑残怎么样?
It's always a matter of finding the good language for the job. How about brainfuck ?
C++ 模板滥用。
我最喜欢这个东西的是:
C++ template abuse.
What I like most of this thing:
确实不值得“每日 WTF”,但我无法抗拒使用 Java 创建一个多语言 Hello World :)
为了避免 Google 翻译服务被其他人堆满,这里是正确的输出,这样你就不会需要自己尝试一下;)
Not really worth a "Daily WTF", but I couldn't resist in creating a multi-language Hello World using Java :)
To save the Google Translate service from being stackoverflowed by fellow sopedians, here's right the output so that you don't need to try yourself ;)
强制性 http://www.infiltec.com/jh-wrld.htm
Obligatory http://www.infiltec.com/j-h-wrld.htm
红宝石
Ruby
这是在 Python 中将抽象发挥到极限的一个极端例子。这是受到dsimcha的解决方案的启发:
Here's an extreme case of taking abstraction to the limit in Python. This is inspired by dsimcha's solution:
Perl,避免误用类的诱惑:
Perl, avoiding the temptation to misuse classes:
本着代码重用的精神,我提出了
sh
版本(需要 sh、wget、zcat、tar、make 和 C 编译器)。In the spirit of code-reuse, I present the
sh
version (requires sh, wget, zcat, tar, make and a C compiler).Malbolge 版本可能会令人感兴趣:
The Malbolge version might be of interest:
不完全是“Hello World”,但同样是 企业 FizzBuzz(用 C# 编写)。
Not exactly "Hello World", but along the same lines is Enterprise FizzBuzz (written in C#).
PHP,1812 个字符
PHP, 1812 chars
等等,没有 HQ9+ 吗?
wait, no HQ9+?
Objective-C
这不需要很多代码,但效率非常低:)
Objective-C
This isn't necessary a lot of code, but it's pretty darn in-efficient :)