tag:blogger.com,1999:blog-5819005.post2341809162880844230..comments2024-04-20T22:33:51.013-07:00Comments on Programming and politics: Diophantine EquationAnonymoushttp://www.blogger.com/profile/08698131967747444207noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-5819005.post-13442300846202795512008-06-18T07:59:00.000-07:002008-06-18T07:59:00.000-07:00I don't think that solution works. I tried it for ...I don't think that solution works. I tried it for n=5 and c=[1,2], i.e. solutions to a + 2b = 5. It gave 8, but there are clearly only 3 solutions (1,2), (3,1), and (5,0).Anonymoushttps://www.blogger.com/profile/08698131967747444207noreply@blogger.comtag:blogger.com,1999:blog-5819005.post-86893453150113121912008-06-18T01:07:00.000-07:002008-06-18T01:07:00.000-07:00My first cut Java solution:int solve(int total, in...My first cut Java solution:<BR/><BR/>int solve(int total, int[] coefs)<BR/>{<BR/> if (total == 0) return 1;<BR/> if (total < 0) return 0;<BR/><BR/> int num = 0;<BR/> for (int value : coefs) <BR/> {<BR/> num += solve(total - value, coefs);<BR/> }<BR/><BR/> return num;<BR/>}<BR/><BR/><BR/>I wasn't completely sure why you needed to manipulate the array of coefficients, except for perhaps an optimization.<BR/><BR/>Having said that, I don't know (with a capital K) that my solution above works.willrhttps://www.blogger.com/profile/16680121153623516973noreply@blogger.comtag:blogger.com,1999:blog-5819005.post-13374419098633401792008-04-27T21:09:00.000-07:002008-04-27T21:09:00.000-07:00Yes, an iterative solution usually has better perf...Yes, an iterative solution usually has better performance than a recursive one. I welcome other folks to post their own solutions, in Ruby or any other programming language they like.Anonymoushttps://www.blogger.com/profile/08698131967747444207noreply@blogger.comtag:blogger.com,1999:blog-5819005.post-52499092305581756332008-04-24T19:43:00.000-07:002008-04-24T19:43:00.000-07:00Nice post! good algorithm. It is more faster to ru...Nice post! good algorithm. It is more faster to run a program when you use recursive algorithm rather than a iterative algorithm or solution.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5819005.post-73664211202624898402008-04-24T19:40:00.000-07:002008-04-24T19:40:00.000-07:00Good algorithm! When your solution takes time to c...Good algorithm! When your solution takes time to compile or execute, the only problem is that your algorithm to solve the problem is slow. Recursive algorithm must be made and use some functions that are predefined or available in the programming language that you are using to run the program faster. I prefer to use those advance programming language because hey have lots of available functions and you don't need to make your own function.Anonymousnoreply@blogger.com