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

yujing_z · 2014年01月04日 · 最后由 hexawing 回复于 2014年05月23日 · 8386 次阅读
本帖已被管理员设置为精华贴

各路大神用各路语言打印出来,虽然 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!

祝大家新年快乐~

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

太喜庆了。。赞!!

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

"Happy new year to you!".sum

Python 是来卖萌的么

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

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

RUBY

'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.length

js

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

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

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

shell

date +%Y

大伙能不用 Time.new.year 不

写的非常漂亮!!

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

js

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

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

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

'bbc'.to_i ?d.hex

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

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

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

28 楼 已删除
29 楼 已删除

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

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)
需要 登录 后方可回复, 如果你还没有账号请 注册新账号