A particularly geeky strip from XKCD:
Any suggestions on how one might solve this problem in R?
XKCD: NP-Complete
« Benford's Law, Zipf's Law and the Pareto Distribution | Main | Thoughts on UseR! 2009 »
You can follow this conversation by subscribing to the comment feed for this post.
The comments to this entry are closed.
Brute force works for me:
Posted by: Allan Engelhardt | July 10, 2009 at 13:14
I can’t believe I just wrote that. Must be the heat. This must be the most elementary mistake in numerical analysis. Try this version instead:
I'll go and kill myself now....
Posted by: Allan Engelhardt | July 10, 2009 at 13:40
Wait a minute, if repeats are allowed, then you have to have different utilities for second replicate. Decreasing marginal returns. Where are you getting your item utilities from?
Posted by: Chris P | July 12, 2009 at 16:33
A marginally better solution exists by reducing the problem 'dynamically.' I have implemented this as a program for the subset sum problem but this versio n assumed repetitions are not allowed. An adaptation to allow repeats should still work.
The program and a pdf version of a flowchart for it are available at;
www.cybase.co.uk/wlcs/Software.html
Posted by: Stephen Le Guen | August 19, 2009 at 04:47
Looking at the answer given by Allan the solution is incorrect!
3.55 + 5.80 + 5.80 = 15.15
Also the answer above totals 15.15, but the original problem found no solution only as 15.15, he apparently tried again with the second target sum.
My program does not search for solutions with duplicates, but allows duplicate alues to be entered. Doubling up eaxh entry finds the solution
2.15 + 3.55 + 3.55 + 5.80 = 15.05
but the values are entered as whole numbers.
Steve
Posted by: Stephen Le Guen | August 21, 2009 at 06:12