Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Project Euler Design Pattern

Is there a design pattern that lends itself to building a foundation of components to help solve Project Euler problems? I've solved ~30 issues - and I find that I'll need to re-use functionality that was previously written (e.g primality checks). Instead of writing static methods in a utility class, I was thinking of having a calculator interface - implemented by various concrete classes that will solve different sub problems. I could then build on that as I solve increasingly complex problems - maybe? Does anyone have any good suggestions? I'm solving the problems in Java.

like image 212
Amir Afghani Avatar asked Apr 27 '12 20:04

Amir Afghani


2 Answers

There are some functions that come in handy repeatedly, like for generating primes. You could keep a file with useful functions in them. Beyond that I don't think there is any benefit. Project Euler problems are more about the math than they are about complex programming, I expect that if you have to write a lot of code you are doing it wrong.

like image 197
Nathan Hughes Avatar answered Oct 17 '22 14:10

Nathan Hughes


The classic pattern for this kind of things is the Template design pattern, but you can build it thinking in other design patterns like for example Visitor, it depends on your needs and taste. You may find useful this link: Template method pattern

like image 31
Juan Alberto López Cavallotti Avatar answered Oct 17 '22 13:10

Juan Alberto López Cavallotti