lib/multiples/multiples_enumerator.rb in multiples-0.1.2 vs lib/multiples/multiples_enumerator.rb in multiples-0.1.3
- old
+ new
@@ -4,16 +4,21 @@
def new a, b
@a, @b = (a..Float::INFINITY).step(a), (b..Float::INFINITY).step(b)
@palindrome_length = a + b - 1
@stack = [[@a.peek, @b.peek].min.to_i]
send :build_palindrome
- return MultiplesEnumerator.new(@stack.reject(&:zero?))
+ return MultiplesEnumerator.new(@stack)
end
private
def build_palindrome
until @stack.length == @palindrome_length
- @stack << step
+ value = step
+
+ # Palindrome completed! Even numbers used!
+ break if value.zero?
+
+ @stack << value
end
end
def step
val = [@a.peek, @b.peek].max - [@a.peek, @b.peek].min