August 23, 2024

P31 - Determine whether a given integer number is prime.

> p31:isprime(7).
    true

erlang

-module(p31).
-export([isprime/1]).

isprime(N) ->
    Less = lists:seq(2, round(N/2)),
    lists:all(fun(X) -> N rem X /= 0 end, Less).
Be first to comment
Leave a reply