3 ms·
Ignoring that this only works if "\r" works, here's a shorter Ruby version without even trying hard: (1..100).each{|i|e=[["fizz"][i%3],["buzz"][i%5]].join;puts
by vidarh 9y ago
Ignoring that this only works if "\r" works, here's a shorter Ruby version without even trying hard:
(1..100).each{|i|e=[["fizz"][i%3],["buzz"][i%5]].join;puts(e[0]?e:i)}
(array lookup with out-of-range offset returns nil, Array#join produces empty strings for nil elements, and accessing element 0 in a zero length string returns nil.