Created
January 28, 2014 17:32
-
-
Save colinrymer/8672209 to your computer and use it in GitHub Desktop.
The included code is dedicated to the public domain by the author, Colin L Rymer, in accordance with CC0 1.0 Universal Public Domain Dedication - http://creativecommons.org/publicdomain/zero/1.0/
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 String | |
def palindrome? | |
!!(self =~ /\A(?<p>| \w | (?: (?<l>\w) \g<p> \k<l+0> ))\z/x) | |
end | |
end | |
def palindrome_count_value(int) | |
int.to_s(2).palindrome? ? 1 : 0 | |
end | |
range = ARGV[0].to_i..ARGV[1].to_i | |
puts range.reduce(0) { |count, int| count + palindrome_count_value(int) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment