Skip to content

Instantly share code, notes, and snippets.

@hoffmanc
Created July 27, 2010 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoffmanc/492208 to your computer and use it in GitHub Desktop.
Save hoffmanc/492208 to your computer and use it in GitHub Desktop.
primes = (1..10000).to_a.delete_if {|n| ('1' * n) =~ /^1?$|^(11+?)\1+$/}
bases = Hash.new
(2..20).each do |i|
ary = []
primes.each do |j|
str = j.to_s(i)
mid = str.length / 2
p1 = str[0..mid-1]
mid = str.length % 2 > 0 ? mid + 1 : mid
p2 = str[mid..-1]
ary.push(j) if(p1 == p2.reverse)
end
bases[i] = ary
end
bases.sort {|a,b| b[1].length <=> a[1].length} .each do |k,v|
puts "#{k}: #{v.length}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment