Ruby 打印出数字 2014,但是代码里不能有任何数字 之 Ruby 版

yujing_z · 发布于 2014年01月04日 · 最后由 hexawing 回复于 2014年05月23日 · 5994 次阅读
2847
本帖已被设为精华帖!

各路大神用各路语言打印出来,虽然ruby不是得票最高的但我觉得是最喜庆的。。

原帖在这里 http://codegolf.stackexchange.com/questions/17005/produce-the-number-2014-without-any-numbers-in-your-source-code

准备好了么,lets go!

热身开始

p Time.new.year

一般般,毫无新意,继续

Happy = Time
Happy.new.year

还不错哈,但感觉一点都不生动!再来

Happy = Time
class Time; alias year! year; end

Happy.new.year!

或者再过分一点!

class Have; def self.a; A.new; end; end
class A; def happy; Time; end; end
class Time; alias year! year; end

Have.a.happy.new.year!

我擦,有点吊啊,但你语法不对啊,点是干嘛的

def noop x = nil; end
alias a noop
alias happy noop
alias new noop
alias year! noop
def Have x
    p Time.new.year
end

Have a happy new year!

这都罩不住你?

def noop x = nil; end
eval %w[we wish you a merry christmas! christmas and a happy new].map{|x|"alias #{x} noop"}*"\n"
def year!; p Time.new.year; end

we wish you a merry christmas! we wish you a merry christmas!
we wish you a merry christmas and a happy new year!

祝大家新年快乐~

共收到 29 条回复
121

coool~

3464

哈哈哈

3

这 Ruby 代码,写的太欢乐了。

1232

太喜庆了。。 赞!!

162

排名第2的Python版本也很cool啊,不过用ruby只要一个函数,感觉有点作弊,哈哈:

"Happy new year to you!".sum
96

Python 是来卖萌的么

96

Unicode Code Point 算不算 JavaScript:'\u07DE'.charCodeAt() Ruby/Python/PHP:ord('\u07DE') Java/CSharp:(int)'\u07DE'

16进制字面量算不算 JavaScript/Ruby/Python/PHP/Java/CSharp:0x7DE

96

RUBY

'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.length
96

js

_=++[[]][+[]],__=_+_,____=__+__,___=+[[]]
alert(__+''+___+''+_+''+____+'');
547643

#10楼 @personball 这个可以当做某高校计算机考题了

96

膜拜!

5700

["ne","","w","year"].map{|x| x.size}.join("")

96

heihei

96

shell

date +%Y
96

大伙能不用Time.new.year不

9606

写的非常漂亮!!

4316

shell的熟悉 @honryou

96

"\xDE\a".unpack('S').first

96

js

alert([!+[]+!+[]]+[+[]]+[+!+[]]+[!+[]+!+[]+!+[]+!+[]]);
8904

哈,总感觉有Ruby的世界真美好!

11112

觉得最后的代码很厉害的样子,但是也很简单

10073

'bbc'.to_i ?d.hex

3

嗯?@Yujing_Z 换头像了啊,从萌宠换成萌妹子了啊。

2847

#25楼 @lgn21st 社区头像管理员你好,巨人看多了,觉得三笠太萌了

3

#26楼 @Yujing_Z 被你认出我的真身了,我的确是社区头像管理员。

28楼 已删除
29楼 已删除
7638

array = %W(zero one two three four) array.indexof('two').to_s + array.indexof('zero').to_s + array.indexof('one').to_s +array.indexof('four').to_s

2220

p (Math.asin(Math.cos("a".to_i)).to_i<<(Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i))-(Math.asin(Math.cos("a".to_i)).to_i<<(Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i+Math.asin(Math.cos("a".to_i)).to_i))-(Math.asin(Math.cos("a".to_i)).to_i<<Math.asin(Math.cos("a".to_i)).to_i)

或者写正常一点……

z = Math.asin(Math.cos("a".to_i)).to_i
p (z<<(z+z+z+z+z+z+z+z+z+z+z))-(z<<(z+z+z+z+z))-(z<<z)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册