Skip to content

Instantly share code, notes, and snippets.

@k-hamada
Created April 11, 2011 09:31
Show Gist options
  • Save k-hamada/913287 to your computer and use it in GitHub Desktop.
Save k-hamada/913287 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# vim:set fileencoding=UTF-8:
require 'date'
range = (Date.parse("1900-01-01") .. Date.today)
stop = [*(1 .. 9), 11, 22]
result = Hash[stop.map{|i| [i, []]}]
def plus(arg)
arg.to_s.each_char.select{|s| s =~ /\d/}.map(&:to_i).inject(:+)
end
range.each do |day|
i = day
until stop.include?(i)
i = plus(i)
end
result[i].push day
end
candidate = range.to_a.size.to_f
result.keys.sort.each do |key|
value = result[key].size
puts "#{key} => #{value} (#{(value / candidate * 100).round}%)"
end
1 => 4514 (11%)
2 => 1046 (3%)
3 => 4513 (11%)
4 => 3027 (7%)
5 => 4517 (11%)
6 => 4519 (11%)
7 => 4518 (11%)
8 => 4518 (11%)
9 => 4515 (11%)
11 => 3466 (9%)
22 => 1488 (4%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment