Jump to content

Primality by trial division: Difference between revisions

(Correction error for 3 aarch64 assembly)
Line 1,809:
=== Recursive ===
{{trans|Go}}
{{works with|langur|0.8.1}}
<lang langur>val .isPrime = f(.i) {
val .n = abs(.i)
if .n <= 2: {return .n == 2
return .n == 2
}
 
val .chkdiv = f(.n, .i) {
if .i x .i <= .n {
return .n remndiv .i != 0 and self(.n, .i+2)
}
return true
}
 
return .n remndiv 2 != 0 and .chkdiv(.n, 3)
}
 
Line 1,830 ⟶ 1,829:
{{trans|Perl 6}}
following the Perl 6 example, which states, "Integer $i is prime if it is greater than one and is divisible by none of 2, 3, up to the square root of $i" (plus an adjustment for the prime number 2)
{{works with|langur|0.8.1}}
<lang langur>val .isPrime = f .i == 2 or .i > 2 and not any f(.x) .i remdiv .x == 0, pseries 2 to .i ^/ 2
 
writeln where .isPrime, series 100</lang>
1,006

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.