Last active
April 2, 2017 20:47
-
-
Save ilnurnasyrov2/e69f47081dffcf30a673537ea8f72496 to your computer and use it in GitHub Desktop.
Fizz buzz without divison
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
require "active_support/core_ext/object/blank" | |
class FizzBuzzChecker | |
def initialize(point, point_name) | |
@point_name = point_name | |
@point = point | |
@current = 1 | |
end | |
def check | |
if @current == @point | |
@current = 1 | |
@point_name | |
else | |
@current += 1 | |
nil | |
end | |
end | |
end | |
three = FizzBuzzChecker.new(3, "Fizz") | |
five = FizzBuzzChecker.new(5, "Buzz") | |
(1..100).each do |n| | |
puts [three.check, five.check].join.presence || n | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment