Weekly Challenges

Solve the challenge, share your solution and summit the ranks of our Community!

Also available in | Français | Português | Español | 日本語
IDEAS WANTED

Want to get involved? We're always looking for ideas and content for Weekly Challenges.

SUBMIT YOUR IDEA

Challenge #52: Solving the Knapsack Problem

mithily
Asteroid
Spoiler
hard
lwolfie
Bolide

I wanted to practice with a new tool.  I'm still not sure I fully used the optimization tool but I have a better idea now. 

olga_strubbe
Bolide

2023-10-12_13-06-51.png

I used a similar approach in solving the challenge as in the solution provided.  My macro is a step simpler. 

Tgigs
Asteroid

My solution attached.

 

Referenced the provided solution, as I am still improving my macro skills. This was a good exercise to help me better understand macros.

 

Spoiler.PNG

fluteman
Comet

I applied Record ID to the original record set 1-5.

 

Then we created a combination and gave it a unique ID. I couldn't find a fast tool that did that so I wrote up the combinations as text input controls such as Combo ID 1 = 1,2 | Qty 2

...

Combo ID 21 = 2,3,4,5 | Qty 4

 

And then I ran through several joins to combine the different combinations through the combination ID.

 

We totaled these up to get the total kgs

 

Throttled to less than 15 kgs. Created a table with Qty of items; Total kgs of those items and then total Price.

 

The Output #2  I was unsure about, so I divided the Price by the Kgs to get the Price per kg to get the best value?

 

I suspect if you wanted, you could apply an iterative macro to create the combinations nested iteration loops within loops and get all the combinations; you would include 0....

 

IT1 0 IT2 0 IT3 0 IT4 1-5

IT1 0 IT2 0 IT3 1-5 IT4 0-5

...

IT1 1-5 IT2 0-5 IT3 0-5 IT4 0-5

 

That would create +1000 permutations

 

Batch Macros: (filter by qty involved)

You would then create five flavours of total Kgs and total Price combinations by Combination ID

4,3,2,1 Qty.,

 

Union the output into one table

 

Then perform your 15 kg check.

 

Then spit out your table by combo id -  if you need the detail, join to the combo id table.

 

 

Used a macro for this? Am I suppose to do it this way???

sknman92
Asteroid
Spoiler
Screenshot 2024-02-23 151043.png

my solution! couldn't figure out a way to make it work with an iterative macro without overcomplicating it with diversions and stuff - so went the simpler route

aatalai
Magnetar

bit messy but got there, tried to use the optimization tool under prescriptive but it didn't seem to work

asultanov
Asteroid
Spoiler
Not very dynamic, but it works so...
Screenshot 2024-03-22 150710.png
AllexJia
Asteroid

works for this data set

Spoiler
1.png2.png