Skip to content

Commit e60df2b

Browse files
authored
Merge pull request #27 from ImanMontajabi/master
added Julia language "prime.jl"
2 parents 096770f + d044ddc commit e60df2b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/prime.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function is_prime(n::UInt32)::Bool
2+
one_num::UInt8 = 1
3+
if n <= one_num
4+
return false
5+
end
6+
startloop::UInt8 = 2
7+
endloop = floor(Int16, sqrt(n))
8+
for i in startloop: endloop
9+
zero_num::UInt8 = 0
10+
if n % i == zero_num
11+
return false
12+
end
13+
end
14+
return true
15+
end
16+
17+
let
18+
start = time()
19+
one_num::UInt8 = 1
20+
c::UInt32 = 0
21+
endloop::UInt32 = 9000000
22+
startloop::UInt8 = 0
23+
for i in startloop: endloop
24+
if is_prime(i)
25+
c += one_num
26+
end
27+
end
28+
println("Primes: $c")
29+
dt = time() - start
30+
println("Time: $dt (s)")
31+
end

0 commit comments

Comments
 (0)