Thursday, December 14. 2006Programming Puzzle #3 SolutionsTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
Because if I link as .py or .pl or whatever, the server will execute it.
Plus, what does it matter? Just name it when you're saving it
Richard, either you're wrong, or you've made a huge discovery in computer science and have won yourself $1,000,000.
I'm guessing its the first one.
While the subset-sum problem, in general, is definitely in NP, even employing techniques like memoization, I'm inclined to believe the constrained version of the subset-sum problem specified in 'Steve the Gambler', where the the subset to find is of a pre-determined size is not in NP.
If the subset that sums to zero can have any number of elements, then there are 2^n subsets to consider. If the subset must contain nine elements, there are 'n choose 9' subsets to consider. I believe that has a polynomial upper-bound function based on the size of n: n choose 9 will always be less than n^9, for example. (There is probably a better bounding function but that one is good enough to demonstrate this problem is in P, not NP) But even if it's polynomial, the brute-force approach will bog down, in either processing time or memory usage, rather quickly.
Good point Cameron. I was referring to the general case above, but it appears that you're most likely correct. In 1986 a paper[1] appeared remarking that the Bounded Subset Sum Problem is usually solvable in polynomial time. This should place it in the BPP[2] class of problems, which Niall[3] informs me are all usually in P.
Thank for your comment, Des [1]http://portal.acm.org/citation.cfm?id=8894.8897 [2]http://en.wikipedia.org/wiki/BPP [3]http://www.minds.may.ie/~xebedee/academic.html
Here is my Visual FoxPRO solution:
http://www.strijewski.com/puzzle3.txt It only has 9 command lines, and if one runs it for a number of days where there are NO solutions, it will list the top 10 best solutions. What do you think?
Ehm, just stumbled in this fine blog of yours.. And just wanted to be picky on one small thing... NP does not mean "Non-Polynomial", but "Non-deterministically Polynomial", i.e. with a polynomial solution on a non-deterministic turing machine... That's the whole point about P=NP, if a NP problem can be put in P (polynomial on a deterministic TM)...
|
About:Switch to Dark on Light!
This website is the online diary of me, Des Traynor, a User Experience Researcher in Dublin, Ireland. I work with Contrast. I usually write on 5 topics: I update about 3-4 times per month. Be sure to subscribe so you don't miss this good stuff. If this is your first time here, check out the archives.My official homepage provides more information about who I am, and what I research. You can contact me at destraynor [at] gmail [dot] com Quicksearch |