Skip to content

Instantly share code, notes, and snippets.

@thorn
Created January 18, 2016 18:21
Show Gist options
  • Save thorn/432180c794a23b6f5bbe to your computer and use it in GitHub Desktop.
Save thorn/432180c794a23b6f5bbe to your computer and use it in GitHub Desktop.
Попытка решить простую задачу https://www.facebook.com/aaskerych/posts/1133740353333561
result = 2017.times.inject(Hash.new(0)) do |res, year|
year.to_s.each_char do |char|
res[char] += 1
end
puts "#{year} => #{res}"
res
end
# 0 => {"0"=>1}
# 1 => {"0"=>1, "1"=>1}
# 2 => {"0"=>1, "1"=>1, "2"=>1}
# 3 => {"0"=>1, "1"=>1, "2"=>1, "3"=>1}
# 4 => {"0"=>1, "1"=>1, "2"=>1, "3"=>1, "4"=>1}
# 5 => {"0"=>1, "1"=>1, "2"=>1, "3"=>1, "4"=>1, "5"=>1}
# 6 => {"0"=>1, "1"=>1, "2"=>1, "3"=>1, "4"=>1, "5"=>1, "6"=>1}
# 7 => {"0"=>1, "1"=>1, "2"=>1, "3"=>1, "4"=>1, "5"=>1, "6"=>1, "7"=>1}
# 8 => {"0"=>1, "1"=>1, "2"=>1, "3"=>1, "4"=>1, "5"=>1, "6"=>1, "7"=>1, "8"=>1}
# 9 => {"0"=>1, "1"=>1, "2"=>1, "3"=>1, "4"=>1, "5"=>1, "6"=>1, "7"=>1, "8"=>1, "9"=>1}
# 10 => {"0"=>2, "1"=>2, "2"=>1, "3"=>1, "4"=>1, "5"=>1, "6"=>1, "7"=>1, "8"=>1, "9"=>1}
# 11 => {"0"=>2, "1"=>4, "2"=>1, "3"=>1, "4"=>1, "5"=>1, "6"=>1, "7"=>1, "8"=>1, "9"=>1}
#
# .......
#
# 2016 => {"0"=>519, "1"=>1609, "2"=>619, "3"=>602, "4"=>602, "5"=>602, "6"=>602, "7"=>601, "8"=>601, "9"=>601}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment