Given a set of numbers, find the minimum multiple sum that an arbitrary number fits into
- number in the set can be used multiple times (or not at all) to achieve a "sum"
- the set of numbers may be any positive decimal (i.e.
1, 4, 4.5
) - given/arbitrary number threshold can be any decimal (i.e.
5
)
Alternate phrasing:
Find the combination of multiples that a given number can fit with the smallest remainder
Find the smallest "sum" that a number can round up to
The actual numbers used in each combination themselves are unimportant to this specific challenge
- Though this could be fun to work out, too ^
Goal is to find the minimum "sum" (either the exact or rounded-up total); however, I would be happy to explore/learn the other factors
Other solutions seem to work backwards from an exact sum
Algorithm for calculating number of fitting boxes
- not exactly a min-change coin problem
Others say variants of subset sums problem
Naive pseudo thinking to problem-solve at the moment:
- Get multiples of each
- Progressively increment sums of combinations all the elements (/ combinations of multiples of the elements; not sure of the best way to do this )
- Stop when each sum-finder has passed over the given number (threshold)
mod
to compare the smallest remainder that has passed over the given number i. may not need this step depending on how the combinations were built up together/separately- Sum found
Thinking there may be a mathematical solution for this or other obvious python examples
https://www.geeksforgeeks.org/find-smallest-range-containing-elements-from-k-lists/
Subset whose sum is the smallest sum over a specific threshold - I think this dynamic programming closely resembles the challenge here; however, am at a bit of a hurdle on how to proceed on progressively combining/multiplying (+memoizing) all the potential combinations of the elements upwards in a pragmatic way.
Does recursively subtracting backwards work well in this type of problem?
Sample test cases
- Set
[1, 4, 4.5]
with arbitrary number5
; least sum =5
(4 + 1) - Set
[1, 4, 4.5]
with arbitrary number5.1
; least sum =5.5
(4.5 + 1) - Set
[20, 40, 9001]
with arbitrary number88
; least sum =100
(40 + 40 + 20 or 20 + 20 + 20 + 20 + 20, or etc) - Set
[20, 40, 9001]
with arbitrary number145
; least sum =160
(40 + 40 + 40 + 40 or 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20, or etc) - Set
[20, 40, 9001]
with arbitrary number9000
; least sum =9000
(40 * 225, etc, I think) - Set
[20, 40, 9001]
with arbitrary number9001
; least sum =9001
(9001, to exemplify cases with strange non-divisible components, given an arbitrary set) - Set
[20, 40, 9001]
with arbitrary number18002
; least sum =18002
(9001 + 9001) - Set
[100, 300, 420]
with arbitrary number101
; least sum =200
(100 + 100) - Set
[100, 300, 420]
with arbitrary number398.001
; least sum =400
(300 + 100) - Set
[100, 300, 420]
with arbitrary number404
; least sum =420
(420)
Thank you for any additional context, pointers, or simple pseudocode solutions you can help with.