Skip to content

Commit

Permalink
minor refactor in order to make the count method smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
giusepped committed Nov 24, 2015
1 parent 9314987 commit 31a961f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions counter.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require_relative './lib/palindrome_counter.rb'

counter = PalindromeCounter.new

Dir.glob('test_files/*.txt') do |test_file|
Dir.glob('**/*.txt') do |test_file|
counter = PalindromeCounter.new
range_numbers = File.foreach(test_file).first(2)
start = range_numbers[0].chomp
finish = range_numbers[1]
Expand All @@ -11,4 +10,4 @@
puts "Range: #{start}..#{finish}"
puts "Palindromes: #{palindrome_count}"
puts "\n"
end
end
3 changes: 1 addition & 2 deletions lib/palindrome_counter.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
class PalindromeCounter

def initialize
@counter
@counter = 0
end

def count(start, finish)
@counter = 0
(start..finish).each do |num|
@counter += 1 if check_palindrome_recursive(num.to_s)
end
Expand Down

0 comments on commit 31a961f

Please sign in to comment.