Project Euler problems
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
catch.hpp
p0001.rkt
p0002_stream.rkt
p0003.py
p0003.rkt
p0004.py
p0004.rkt
p0005.rkt
p0006.rkt
p0007.rkt
p0008.rkt
p0008_number.txt
p0008_number_spaces.txt
p0009.rkt
p0010.rkt
p0011.rkt
p0011_data.txt
p0012.rkt
p0013.rkt
p0013_data.txt
p0014.rkt
p0014_path.rkt
p0015.rkt
p0016.rkt
p0017.cpp
p0018.rkt
p0018_data1.txt
p0018_data2.txt
p0019.cpp
p0020.hs
p0021.hs
p0022.hs
p0022_names.txt
p0023.cpp
p0023.hs
p0023.rkt
p0024.cpp
p0024.recursive.cpp
p0025.lisp
p0025.txt
p0026.cpp
p0027.cpp
p0028.cpp
p0029.cpp
p0030.cpp
p0031.cpp
p0032.cpp
p0033.cpp
p0034.cpp
p067_triangle.txt

README.md

Project Euler problems

Just me working through the project Euler problems. I often try out different languages and paradigms as I go so the code reflects that. It reflects a short flirtation with functional programming (programs in racket and Haskell), a short foray into Common Lisp and then a regression back to C++. There are rarely any Python programs as I use that extensively during the day.

Interesting algorithms/implementations

  • p0024.cpp - "forward backward" algorithm for generating permutations p0024.recursive.cpp - implemented as a recursive calls. Trades off readability and elegance for speed and memory also p0032.cpp

Notes on the problems

  • p34 Interesting that there are only two such numbers ever: 145 and 40585

Racket concepts and the files in which they are implemented

Default values

(define (foo [x 1] [y 2]) ... eg. p5.rkt

Structures

freecell.rkt, p15.rkt

Fixtures for tests

Not completely fixtures, but you can put defines inside a test-case so that you can set up data structures and then operate on them. e.g: p13.rkt

Reading files

open-input-file read-line string-split

e.g. p11.rkt

Sum of row/column of a matrix

array-axis-sum e.g. p13.rkt

Accessing multiple values returned from a function

See http://stackoverflow.com/questions/20556746/how-do-i-do-anything-with-multiple-return-values-in-racket/20556950#20556950

Use let-values. See p13.rkt, algorithms/merge_sort.rkt

Conditional blocks

Use cond. see algorithms/sort_algorithms.rkt, p15.rkt

Timing code

Use (time ...) e.g. p12.rkt p15.rkt

Memoization

Use the memoize package. e.g. p15.rkt

Haskell concepts and the files in which they are implemented

File I/O

(From an introduction here)

C++

All code can be compiled with g++ --std=c++14 pXXXX.cpp -o current

const member function

p0032.cpp, p0034.cpp

To be able to call a function on a const object, you need to promise the compiler that the function will not modify the object. To do that, you mark the function with the keyword const after its argument list.