Options

Code to find number combination(s) for a given total

bhalpinbhalpin Member Posts: 309
edited 2015-03-03 in NAV Three Tier
Hi.

I have a set of numbers and I need to find a subset that equals, or is less then a given value.

For example, I might have the numbers 2, 6, 8, 10, 16, & 22, and need to find a combination that totals 40. The answers would be 2 + 16 + 22 = 40, or 8 + 10 + 22 = 40, or 2 + 6 + 10 + 22 = 40. If my target was 41, then either of these would be acceptable too.

Has anyone seen C/AL code that accomplishes this?

Thanks!

Comments

  • Options
    bhalpinbhalpin Member Posts: 309
    Update:

    It looks like the Excel add-in "Solver" has the function I need. So, in theory, I could manipulate Excel from within NAV to get my answer.

    Has anyone gone anywhere near this though NAV? Or, or does anyone know of any examples that manipulate Excel beyond the usual loading of a spreadsheet?

    Thanks!
Sign In or Register to comment.