Skip to content

Instantly share code, notes, and snippets.

@kenzo0107
Last active November 24, 2019 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenzo0107/8b32c9b56bd755b2c0e072d063ce0c0c to your computer and use it in GitHub Desktop.
Save kenzo0107/8b32c9b56bd755b2c0e072d063ce0c0c to your computer and use it in GitHub Desktop.
def div_each(r)
b = []
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)
b << a
b << r if p.size - 1 == index
}
return b
end
p div_each(123_456) # [12, 0, 1, 1, 0, 4, 1, 0, 1, 1, 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment