#!/usr/bin/ruby
def sum_all_doubles(tens)
sum=0
1.upto(tens) do |i|
(1..9).each do |n|
sum+=(n.to_s*i).to_i
end
end
sum
end
def run()
sum=sum_all_doubles(100)-45 #45 because the sum of 1+2+3...+9 is 45 and the problem is 10 < n < 10^100
possible=[102564, 128205, 142857, 153846, 179487, 205128, 230769,1012658227848,1139240506329,105263157894736842,157894736842105263,210526315789473684,263157894736842105,315789473684210526,368421052631578947,421052631578947368,473684210526315789,1014492753623188405797,1159420289855072463768,1304347826086956521739,1034482758620689655172413793,1379310344827586206896551724,1724137931034482758620689655,2068965517241379310344827586,2413793103448275862068965517,2758620689655172413793103448,3103448275862068965517241379,102040816326530612244897959183673469387755,122448979591836734693877551020408163265306,163265306122448979591836734693877551020408,183673469387755102040816326530612244897959,10112359550561797752808988764044943820224719,1016949152542372881355932203389830508474576271186440677966,1186440677966101694915254237288135593220338983050847457627,1355932203389830508474576271186440677966101694915254237288,1525423728813559322033898305084745762711864406779661016949]
(1..16).each do |i|
possible.each do |a|
attempt=(a.to_s*i).to_i
sum+=attempt if attempt<10**100
end
end
sum
end
puts run()