Skip to content

Instantly share code, notes, and snippets.

@bolshakov
Created June 2, 2018 07:13
Show Gist options
  • Save bolshakov/1b7b9ce62ad027f96edd98e313e197eb to your computer and use it in GitHub Desktop.
Save bolshakov/1b7b9ce62ad027f96edd98e313e197eb to your computer and use it in GitHub Desktop.
code = <<-RUBY
c = fzbz = -> v {
s = v % 3 < 1 ? 'Fizz' : ''
v % 5 < 1 && s << 'Bazz'
v < 1 ? [] : c[v - 1] + [s == '' ? v : s]
}
RUBY
fzbz = eval(code)
puts code.gsub(/\s/, '').length
print fzbz.(15)
# > ruby fzbz.rb
# >> 70
# >> [1, 2, "Fizz", 4, "Bazz", "Fizz", 7, 8, "Fizz", "Bazz", 11, "Fizz", 13, 14, "FizzBazz"]%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment