Skip to content

Commit

Permalink
Add Prime Number in Julia (#4480)
Browse files Browse the repository at this point in the history
* passes all tests except large composite

* passing all tests for prime-number

* Added prime-number in Julia

* Add Prime Number in Julia
  • Loading branch information
JacobWoodbury authored Feb 13, 2025
1 parent 82a5abe commit d5fb8f8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions archive/j/julia/prime-number.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function err()
return "Usage: please input a non-negative integer"
end


function isPrime(num)
# handle 0 and 1
if num <= 1
return "composite"
end

# default handler
for i in 2:sqrt(num) #loop starting at 2, ending at the squareroot of the input
if (num % i == 0)
return "composite"
end
end
return "prime"
end

#check for a valid input
try
n = parse(Int, ARGS[1])
if n < 0
println(err())
else
println(isPrime(n))
end
catch e
println(err())
end

0 comments on commit d5fb8f8

Please # to comment.