I'm new to Erlang and just had a question. I've already looked here on StackOverflow and done a lot of Googling.
I'm trying to write a function that takes two parameters and returns the prime numbers between them. My biggest issue is with Prime testing (checking if a number is prime). I fix the rest of the stuff later.
Here's the code I have so far:
-module(ListPrime).
-export([primeList/2]).
primeList(0, 0)->
io:format("No prime numbers here ~s~n", [0]);
`
primeList(Start, Finish)->
CheckPrime = Finish rem Start,
if
Start =< Finish, CheckPrime == 1 -> primeList(Start, Finish-1)
end.
Basically what I'm trying to do is:
Check if Finish is a prime number.
If not, move on to the next number (Finish-1).
Continue until the base case has been reached.
It compiles but it obviously doesn't do what I want it to do because I don't know how to check if a number is prime.
I know what the definition of a Prime Number is (a number that is only divisible by itself and 1) but the only thing that comes to mind to write when I think about that definition is:
Finish rem Finish
and line of code works for any number that is used. How do I check if a number is prime in Erlang? Thank you very much.