Last active
November 24, 2019 15:25
-
-
Save kenzo0107/7c50a3fcecc7aa8e25ce9ad58e522137 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def div_hash_each(r) | |
h = {} | |
p = [10_000, 5_000, 2_000, 1_000, 500, 100, 50, 10, 5, 1] | |
p.each_with_index{|d, index| | |
a, r = r.divmod(d) | |
h[d] = a | |
} | |
return h | |
end | |
p div_hash_each(123_456) # {10000=>12, 5000=>0, 2000=>1, 1000=>1, 500=>0, 100=>4, 50=>1, 10=>0, 5=>1, 1=>1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment