Which ten-digit number has the n-th digit representing how many occurrences of the digit (n−1) there are in the number, for all n≤10 ?
Last active
March 1, 2016 16:05
-
-
Save iwan/d4d94396cc72f0bf15bc to your computer and use it in GitHub Desktop.
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 Fixnum | |
def autoref? | |
a = to_s.rjust(10, "0").split("").map(&:to_i) # a = [2,3,1,1,3,4,5,5,1,9] | |
h = Hash[(0..9).map{|e| [e, 0]}] | |
a.each{|e| h[e]+=1} | |
a.each_with_index do |n, i| | |
return false if n!=h[i] | |
end | |
true | |
end | |
end | |
0.upto(10**10-1) do |n| | |
puts n if n%20_000==0 | |
if n.autoref? | |
puts ">>>>#{n}<<<<<" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment