Last active
December 25, 2015 11:29
-
-
Save obfusk/6969436 to your computer and use it in GitHub Desktop.
fizzbuzz
This file contains hidden or 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
| (1..100).each { |x| s=''; s+='Fizz' if x%3==0; s+= 'Buzz' if x%5==0; puts s.empty? ? x : s } |
This file contains hidden or 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
| (1..100).each { |x| puts [-> r { x%3==0?'Fizz':r }, -> r { x%5==0?r.to_s+'Buzz':r }].reduce(nil) { |a,b| b[a] } || x } |
This file contains hidden or 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
| (1..100).each { |x| puts ->r {x%5==0?(r||'')+'Buzz':r}[x%3==0&&'Fizz'] || x } |
This file contains hidden or 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
| (1..100).each {|x| r=x%3==0&&'Fizz'; puts x%5==0?(r||'')+'Buzz':r||x } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment