Skip to content

Instantly share code, notes, and snippets.

@colinrymer
Created January 28, 2014 17:32
Show Gist options
  • Save colinrymer/8672209 to your computer and use it in GitHub Desktop.
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/
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