Skip to content

Instantly share code, notes, and snippets.

@obfusk
Last active December 25, 2015 11:29
Show Gist options
  • Select an option

  • Save obfusk/6969436 to your computer and use it in GitHub Desktop.

Select an option

Save obfusk/6969436 to your computer and use it in GitHub Desktop.
fizzbuzz
(1..100).each { |x| s=''; s+='Fizz' if x%3==0; s+= 'Buzz' if x%5==0; puts s.empty? ? x : s }
(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 }
(1..100).each { |x| puts ->r {x%5==0?(r||'')+'Buzz':r}[x%3==0&&'Fizz'] || x }
(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