✖️ PrimesTables

This is a coding challenge to gather the first n prime numbers and generate a multiplication table for those numbers as output.

🛠️ Setup

  • Install Elixir.
  • Fetch dependencies with mix deps.get.
  • Compile with mix compile.

🏃‍♀️ Running the Project

You can run the project with the following to see a multiplication table printed to std output:

$ mix run -e "PrimesTables.run(3)"
|  x |  2 |  3 |  5 |
|  2 |  4 |  6 | 10 |
|  3 |  6 |  9 | 15 |
|  5 | 10 | 15 | 25 |

⚗️ Running the Tests

  • Run all the tests for the project with mix test.
  • There's also a test watcher available with mix test.watch.
  • Typespecs can be verified with mix dialyzer.

📝 Notes

  • Structure of the Solution
    • validate input
    • calculate an upper bound
    • find primes
    • take n primes
    • generate table
    • print output
  • Potential Future Work
    • Use a different data structure for the table (instead of list -> string) with a Map or the Nx library, and then use it to produce the string output
    • Build a nice web UI with Phoenix to visualize the algorithm instead of printing to stdout
    • Benchmark finding primes with benchee

📖 Reference