functional programming

*To*: mathgroup at smc.vnet.net*Subject*: [mg62981] functional programming*From*: mike_in_england2000 at yahoo.co.uk*Date*: Sat, 10 Dec 2005 06:02:50 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

Hi All As a long time C++ programmer I am terrible at functional programming. I recently replied to a post on here concerning diophantine equations and provided the following code: dioph[x_, k_] := (5 x)^2 - 2^k*3*(5 + k)^2 - 131*k - 7 Reap[ Do[ Do[ If[dioph[x, k] == 0, Sow[{x, k}];]; , {x, 0, 1000} ] , {k, 0, 1000} ]] Someone else came up with a more efficient way of doing this and it was a nice solution. However my question is this - How could I have rewritten my orginal code using Functional programming? Nothing fancy - just a literal translation using the ideas of functional programming. I tried dioph[x_, k_] := If[(5 x)^2 - 2^k*3*(5 + k)^2 - 131*k - 7 == 0, {x, k}]; Table[dioph[x, k], {x, 0, 10}, {k, 0, 10}]; which is similar to something that was posted on here a while back but I hit the same problem they did - The If statement returns Null when the statement is false so you end up with large lists of Nulls. Not good if I want to look at large ranges of numbers. Any advice would be welcomed Thanks, Mike