Skip to content

Elixir scaffolding for solving, testing and benchmarking the Project Euler problems

Notifications You must be signed in to change notification settings

ryan-senn/elixir-project-euler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elixir Project Euler

Elixir scaffolding for https://projecteuler.net/

This repo is a simple Mix project with boilerplate generated for each problem.

It comes with a mix task to check your solutions against the preconfigured correct answers and a mix task to benchmark your various solution implementations against one another (using the excellent benchee library).

Usage

  • Clone this repo: git clone [email protected]:ryan-senn/elixir-project-euler.git.
  • Navigate to the project with cd elixir-project-euler.
  • Run mix deps.get to install the dependencies (dependency really, just benchee)
  • Run mix problems.generate to generate the boilerplate for each problem.
  • Open ./lib/problem_1.ex in your favourite code editor.
  • Open ./problems.pdf (useful if wishing to do these exercises offline) or follow the commented link at the top (eg. https://projecteuler.net/problem=1) to read up on the problem and implement solution_1
  • Test your solution with mix problem.test 1, where 1 is the problem number. There is a mix t 1 shorthand that does the same (t for test).
  • If you can't find the correct answer and are stuck, you can use the --show flag to display the expected answer.
  • Optional Comment in and implement solution_2. Running mix problem.test 1 will detect the new solution and verify both.
  • Run mix problem.benchmark 1 to see which implementation is more efficient. There is a mix bm 1 shorthand that does the same (bm for benchmark).
  • Optional Implement as many solutions as you want. Make sure to name your solutions solution_{solution_number} with no params and repeat the testing and benchmarking steps above.
  • Move to ./lib/problem_2.ex and repeat the steps above using mix problem.test 2 etc.

Changing the boilerplate for problems

If you don't like the generated boilerplate for each problem, you can change what is generated by editing ./lib/mix/tasks/generate_problems.ex and updating the boilerplate function to your liking.

Once done, run mix problems.generate again. It will fail if the destination file already exists, so either delete the files that you want to overwrite manually or use the --force flag. Note that the --force flag will erase all your existing solutions so be careful!

About

Elixir scaffolding for solving, testing and benchmarking the Project Euler problems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages