Last active
August 29, 2015 14:23
-
-
Save baweaver/88bbbc1a3e3b5dee2610 to your computer and use it in GitHub Desktop.
Ox0dea had a bit of fun, and I wanted to know how he did it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original from Ox0dea - http://irclog.whitequark.org/ruby/2015-06-29#13259662; | |
# Yes, it produces FizzBuzz | |
_=$$/$$;__=_-_;@_=_+_;$_=@_+_;$__=@_+$_;$-_=$__*$_;@__=''<<$-_*($__+$_)+@_;$___=''<<$-_*$__-$__<<$-_*($__+@_)<<@__<<@__;@___=''<<$-_*$__-$_*$_<<$-_*($__+$_)-$_<<@__<<@__;(___=->____{$.+=_;____<<($.%$-_==__ ?$___+@___:$.%$_==__ ?$___:$.%$__==__ ?@___:$.);$.<($__*@_)**@_?___[____]:____})[[]] | |
# Wtf!? Let's disect it then | |
_ = $$ / $$ # PID / PID or 1 | |
__ = _ - _ # 1 - 1 or 0 | |
@_ = _ + _ # 1 + 1 or 2 | |
$_ = @_ + _ # 2 + 1 or 3 | |
$__ = @_ + $_ # 2 + 3 or 5 | |
$-_ = $__ * $_ # 5 * 3 or 15 | |
# Now it's getting denser... | |
@__ = | |
'' << # '' | |
$-_ * ($__ + $_) + @_ # 122 ((15 * (5 + 3)) + 2) z | |
$___ = | |
'' << # '' | |
$-_ * $__ - $__ << # 70 (15 * 5 - 5) F | |
$-_ * ($__ + @_) << # 115 (15 * (5 + 2)) i | |
@__ << # 122 z | |
@__ # 122 z | |
@___ = | |
'' << # '' | |
$-_ * $__ - $_ * $_ << # 66 (15 * 5 - 3 * 3) B | |
$-_ * ($__ + $_) - $_ << # 117 (15 * (5 + 3) - 3) u | |
@__ << # 122 z | |
@__ # 122 z | |
(___ = -> ____ { | |
$. += _ # n - ARGF.lineno - which happens to nicely start at 0 | |
____ << ( | |
$. % $-_ == __ ? # if mod 15 == 0 | |
$___ + @___ : # 'FizzBuzz' | |
$. % $_ ==__ ? # else if n mod 3 == 0 | |
$___ : # 'Fizz' | |
$. % $__ == __ ? # else if n mod 5 == 0 | |
@___ : # 'Buzz' | |
$. # else n | |
) | |
$. < ($__ * @_)**@_ ? # if n < (5 * 2)**2 (100) | |
___[____] : # recall the lambda | |
____ # else return the collection | |
})[[]] # Now call it with an empty array as an accumulator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment