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.

Follow David on Twitter: @revodavid

- academia (41)
- advanced tips (218)
- AI (62)
- airoundups (20)
- announcements (200)
- applications (288)
- beginner tips (106)
- big data (272)
- courses (60)
- current events (126)
- data science (227)
- developer tips (89)
- events (280)
- finance (126)
- government (25)
- graphics (378)
- high-performance computing (115)
- life sciences (35)
- Microsoft (312)
- mlops (4)
- open source (78)
- other industry (58)
- packages (388)
- popularity (54)
- predictive analytics (163)
- profiles (15)
- python (69)
- R (2440)
- R is Hot (8)
- random (464)
- reviews (22)
- Revolution (422)
- Rmedia (136)
- roundups (121)
- sports (55)
- statistics (297)
- user groups (127)

- R on Azure

Developer's guide and documentation - 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