Lucas Garron
Redoing Project Euler over 7 years later.
https://projecteuler.net/problems
- Primary languages:
- Haskell (for concise solutions)
- Mathematica (for fast math)
- C (for fast code)
- Comments at the top: problem number, name, date, sometimes runtime.
- Preferably a self-contained, runnable file.
- Use standard libraries or custom code.
- Print only the integer result. Send (minimal) debug/progress output to
stderr
(e.g. to show progress for slow code, or print out additional info).
- Mathematica
- Calculate an integer, set
result
to it,Print[result]
. - When defining functions, include types like
_Integer
and_List
for type safety.
- Calculate an integer, set
- Haskell:
- Include imports, and only import specific functions.
- Annotate every free-standing function/expression with a type, as well as any appropriate where clauses.
- Code section that ends with the calculation of
result :: Integer
. - Output section using
main = print result
. - If the problem has input:
main = readFile "filename.txt" >>= print . result
.- This makes
result
a function, but it's still pure. result
should probably use an auxiliaryparseInput
function in awhere
clause.
- This makes
- Memoization: use Data.MemoCombinators unless a list is obviously appropriate.
- C
- Use static data structures with initalization methods.
- Have an
int result()
function, only print the result in main. - Free all malloced data.
The idea behind having a consistent variable/function result
is that the code files could be imported/compiled/linked dynamically in the future. (Not sure how to deal with the two possible types for result
in Haskell, yet.)
I'm putting these up on the internet for a few reasons.
For example, it's a way to encourage me to work on my coding style by publishing clean code.
If you're interested in the idioms, decomposition, data structures, and optimizations I use, please feel free to peruse my solutions, but keep in mind that if you're planning to solve these yourself, it's more valuable to do it by yourself first, and then see what others have done.