Any Elixir and/or Erlang wiz kid who could include this language in the primes "competition"

There is an interesting primes “competition” going on using docker containers here (it’s an introduction on how the test works and the first thematicaly similar languages Ada, Pascal and Delphi are tested and ranked):

The github page is here:

The author said that new languages could be added.

Elixir and Erlang is currently missing.

I know Elixir/Erlang can’t win, but it would be nice if we could be included and get a nice result :wink:

2 Likes

Warning: I’m not a wiz kid.

The docker part ist easy and docker is also a handy tool to have in your toolbox.

Say you have a script prim.exs in the working directory

# calculate a prime number and print it out
IO.puts(1+1)

Check that you can run it with elixir prim.exs.

Then you can just run this script inside docker with

docker run -it --rm -v "$PWD":/prim -w /prim elixir:alpine elixir prim.exs

docker will automatically fetch the image “elixir:alpine” from Docker Hub. -v and -w do some magic so that docker sees the host-filesystem. The last part just runs the script inside the container.

2 Likes

I wonder if precomputing the whole array of “primes up to 1,000,000” and putting it in a module attribute would count as “cheating” :stuck_out_tongue:

defmodule VeryCheatingMuchFast do
  @all_the_primes ComputePrimes.all(1_000_000)

  def all_the_primes do
    @all_the_primes
  end
end
9 Likes

Wow, cdesch just added the solution for Elixir. Primes/PrimeElixir/solution_1 at drag-race · PlummersSoftwareLLC/Primes · GitHub

2 Likes

Yep sorry, way too busy with the zig impl to do an elixir one :(. Someone should do erlang because Dave will highlight the syntax differences.

1 Like

You can precompute some primes using the “wheel” technique. The size of the list must be runtime for it to be considered “faithful”.

Might be neat to do something like use the process dict to see if it’s fasterrrr

ok, I got nerdsniped and learned me something about :counters module. 4000x speedup =D

1 Like