tl;dr I want to make an array from the division by 5 results:
20 => [5,5,5,5]
16 => [5,5,5,1]
7 => [5,2]
My current implementation is straightforward yet too large. How can I make it simpler and shorter?
max_count = 5
total_count = input_value
count_array = []
div = total_count / max_count
mod = total_count % max_count
div.times { count_array << max_count }
count_array << mod unless mod == 0
16 => [5,5,5,1]20.divmod(5) #=> [4, 0]. Contains the all the information you require i.e. the quotient and the remainder.