Last active
August 31, 2016 13:32
-
-
Save mcelaney/9910a377c9234fd120fcc64519c97d27 to your computer and use it in GitHub Desktop.
Normalish FizzBuzz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FizzBuzz | |
def self.find_answers_for(max) | |
1.upto(max).each do |n| | |
result = '' | |
result << 'Fizz' if n % 3 == 0 | |
result << 'Buzz' if n % 5 == 0 | |
result = n if result.empty? | |
result | |
end | |
end | |
end | |
puts Benchmark.measure { FizzBuzz.find_answers_for(1000000) } | |
# 0.160000 0.010000 0.170000 ( 0.177896) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment