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.

Got comments or suggestions for the blog editor?

Email David Smith.

Email David Smith.

- academia
- advanced tips
- AI
- announcements
- applications
- beginner tips
- big data
- courses
- current events
- data science
- developer tips
- events
- finance
- government
- graphics
- high-performance computing
- life sciences
- Microsoft
- open source
- other industry
- packages
- popularity
- predictive analytics
- profiles
- python
- R
- R is Hot
- random
- reviews
- Revolution
- Rmedia
- roundups
- sports
- statistics
- user groups

- Find R packages

CRAN package directory at MRAN - Download Microsoft R Open

Free, high-performance R - R Project site

Information about the R project

- @RLangTip

Daily tips on using R - FlowingData

Modern data visualization - Probability and statistics blog

Monte Carlo simulations in R - R Bloggers

Daily news and tutorials about R, contributed by R bloggers worldwide. - R Project group on analyticbridge.com

Community and discussion forum - Statistical Modeling, Causal Inference, and Social Science

Andrew Gelman's statistics blog

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 elementarymistake 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