Skip to content

Instantly share code, notes, and snippets.

@t0yohei
Last active June 17, 2021 14:38
Show Gist options
  • Save t0yohei/3c3b8b6da186121588ff1b766e697f2c to your computer and use it in GitHub Desktop.
Save t0yohei/3c3b8b6da186121588ff1b766e697f2c to your computer and use it in GitHub Desktop.
This is fizz buzz one liner without any `if` sentence
(1..100)
.to_a
.tap { |map| (1..100)
.select{ |i| i % 3 == 2 }
.each { |j| map[j] = 'fizz' } }
.tap { |map| (1..100)
.select{ |k| k % 5 == 4 }
.each { |l| map[l] = 'buzz' } }
.tap { |map| (1..100)
.select{ |m| m % 15 == 14 }
.each { |n| map[n] = 'fizzbuzz' } }
.each { |result| p result }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment