Skip to content

giusepped/palindrome_numbers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Palindrome numbers counter

  • This is a small Ruby app that can be used in the console in order to count the palindrome numbers in a range.

  • The range of number is given in a text file (the first two lines represent the starting and the ending numbers of the range respectively)

Running the application

In your terminal do the following

$ git clone https://github.com/giusepped/palindrome_numbers
$ cd palindrome numbers
$ ruby counter.rb

Test

In order to run the Rspec tests (there are 5 tests that test the same range numbers that are in the test files and one other), do the following

$ rspec

Approach

I created an external class that does the counting in a range. I have two methods for checking if a number (once converted into a string) is a palindrome:

  • the first one uses the reverse ruby in-built method
  • the second one uses recursion

In the main file I first initalise an instance of the class PalindromeCounter.

Then I iterate through the .txt files in the test_files folder and for each one:

  • I get the first two lines and store them into variables start and finish
  • Use chomp on the first variable (because in the file there was a new line)
  • Calculate the count of palindrome numbers in the range
  • Output the name of the file checked, the range and the count of palindromes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages