学校举办比赛, 3 行代码内能完成什么牛叉的事情呢?

2015-11-08 16:09:46 +08:00
 Feiox

语言就常见的那几种吧。不包括 Lisp 家族的语言
规则大概有:
1. 不可引用第三方库,只能使用各个语言的标准库
2. 不能恶意压缩代码
3. 函数声明语句(如 def func():)不算在 3 行之内

那么,能玩出那些新(niu)花(bi)样(a)呢?

11670 次点击
所在节点    程序员
98 条回复
eamars
2015-11-08 17:22:27 +08:00
while True:
input()
print("呵呵,去洗澡")

女神型人工智能
icylogic
2015-11-08 17:24:20 +08:00
居然没人提这个么。

c#:

Func<Func<Func<int, int>, Func<int, int>>, Func<int, int>> Y = f => ((Recursive)(g => (f(x => g(g)(x)))))((Recursive)(g => f(x => g(g)(x))));
var fac = Y(f => x => x < 2 ? 1 : x * f(x - 1));
var fib = Y(f => x => x < 2 ? x : f(x - 1) + f(x - 2));

coffeescript:
Y = (f) -> g = f( (t...) -> g(t...) )
fac = Y( (f) -> (n) -> if n > 1 then n * f(n-1) else 1 )
fib = Y( (f) -> (n) -> if n > 1 then f(n-1) + f(n-2) else n )
wy315700
2015-11-08 17:27:41 +08:00
while(1) fork();
Comdex
2015-11-08 17:33:20 +08:00
关机的代码
Ignotus
2015-11-08 17:38:59 +08:00
import Earth
Earth.destroy()
aalska
2015-11-08 17:40:20 +08:00
sudo rm -rf /
reboot now
wbsdty331
2015-11-08 17:43:26 +08:00
VB
Private Sub Form_Load ()
Shell “ shutdown -s -t 0 ”
End Sub
rcmerci
2015-11-08 17:44:47 +08:00
为什么我觉得这种三行代码得比赛很没意思呢。。
30 行倒是还有点意思
kotokz
2015-11-08 17:45:42 +08:00
很多语言行数无意义。例如 perl awk 的超长 one liner. 例如 javascript 都是压成一行
500miles
2015-11-08 17:46:47 +08:00
print "第一行"
print "第二行"
print "第四行"
Roope
2015-11-08 17:47:33 +08:00
#!/bin/bash
echo "Bye"
init 0
deadEgg
2015-11-08 17:50:08 +08:00
AppURL.logInit(a[b].site), c = navigator.userAgent.toLowerCase(), d = c.indexOf("iphone") > -1, e = c.indexOf("ipad") > -1, f = c.indexOf("android") > -1, f && (a[b].android || a[b].moplus || a[b].chrome) ? AppURL.openUrl(a[b].site, a[b].android, a[b].moplus, a[b].packagename, a[b].chrome) : d && "" != a[b].iphone ? AppURL.openUrl(a[b].site, a[b].iphone, !1) : e && "" != a[b].ipad ? AppURL.openUrl(a[b].site, a[b].ipad, !1) : window.location.replace(a[b].site)
virusdefender
2015-11-08 17:52:12 +08:00
while(1){
fork();
}
wjself
2015-11-08 17:54:36 +08:00
@xiangtianxiao 233,继续编!期待…
ngn999
2015-11-08 17:55:56 +08:00
谁来贴下 bash 的那个一行的无限子进程攻击代码?
bramblex
2015-11-08 17:58:47 +08:00
@icylogic 卧槽,这是我见过最丑的 Y 算子…

要玩组合子当然是上 Haskell 啊…
ngn999
2015-11-08 18:01:04 +08:00
:(){ :|:& };:
cnnblike
2015-11-08 18:02:55 +08:00
js eval 某个地址的 js 代码,想干啥干啥
bramblex
2015-11-08 18:03:58 +08:00
@ngn999 :():&;: 这个? fork 炸弹
ngn999
2015-11-08 18:24:59 +08:00
@bramblex 嗯,是这个参见我楼上的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/234596

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX