An open API service indexing awesome lists of open source software.

https://github.com/jackfirth/clojure-primes

Toy problem for getting familiar with Clojure build tooling and project organization
https://github.com/jackfirth/clojure-primes

Last synced: 2 months ago
JSON representation

Toy problem for getting familiar with Clojure build tooling and project organization

Awesome Lists containing this project

README

          

# clojure-primes [![Build Status](https://travis-ci.org/jackfirth/clojure-primes.svg)](https://travis-ci.org/jackfirth/clojure-primes)

Toy problem for getting more comfortable with Clojure build tooling and ecosystems. Constructs a list of the first `n` primes, then draws a table of multiplying primes by each other prime.

To run, clone the repo and `lein run`. The default app prints a table with the first 15 primes. Built with leiningen 2.x, not tested on leiningen 1.x.

To play around with, clone the repo and `lein repl`, then `(print-prime-table 30)` or however many you want to see.

# Scalability

The biggest drain on performance is IO to the console. `(print-prime-table 1000)` takes a second or so to draw everything. However, notable time complexities are:

- `O(m(n) n^2)` for constructing the multiplication table, where `n` is the size of the largest prime (not the number of primes). One multiplication per prime pair, with each multiplication taking `m(n)` time (not sure how efficient clojure's implementation of arbitrary precision multiplication is).
- `O(mod(p) p^2)` for constructing the first `p` primes, where `mod(p)` is the cost of computing `p mod p`. Note that the `n`th prime is approximately `n / log(n)`, thus `O(p) = O(n / log(n))` making linear time in `p` less than linear time in `n` by a logarithmic factor of `n`. The reason there are `p^2` divisions is because the test for checking if a number is prime based on the primes known so far tests *all* primes known so far, instead of starting at 2 and stopping at the square root of `p`. There's not much point to this optimization currently, because it doesn't do anything about the larger multiplication table time and both computations are dwarfed by IO time.