Message Boards Message Boards

0
|
2144 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Functional approach to the Babbage squares challenge ?

Posted 4 years ago

Hi,

I solved the Babbage squares problem, but it was very painful and my code is embarrassingly ugly.

My first approach was functional, but it was too slow. I basically created all possible tuples and filtered them with transpose@# == # &. I thought it was elegant, but again, too slow.

It occurred to me that in order to improve performance I had to perform the tests progressively, that is at each Cartesian product, not only at the end. I'm pretty sure I know how I could do it with procedural programming. I would use three (since we know the first word) For loops with conditional Continue instructions in each of them. I am confident that would work, but I really want to learn functional programming and I struggle to find the FP equivalent.

I'm not asking for the solution, but can anyone give me a hint of the correct FP approach for this kind of problem?

POSTED BY: Lucien Grondin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract