Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def print_fizz_with_case(arg)
- arg = arg.to_s.split('').map {|x| x.to_i }
- arg.each do |x|
- m3 = x.modulo(3) == 0
- m5 = x.modulo(5) == 0
- puts case
- when (m3 and m5) then 'FizzBuzz'
- when m3 then 'Fizz'
- when m5 then 'Buzz'
- else x
- end
- end
- end
- print_fizz_with_case(100
- (1..100).each do |x|
- m3 = x.modulo(3) == 0
- m5 = x.modulo(5) == 0
- puts case
- when (m3 and m5) then 'FizzBuzz'
- when m3 then 'Fizz'
- when m5 then 'Buzz'
- else x
- end
- end
Add Comment
Please, Sign In to add comment