How to resolve the algorithm Primality by trial division step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Primality by trial division step by step in the zkl programming language
Table of Contents
Problem Statement
Write a boolean function that tells whether a given integer is prime.
Remember that 1 and all non-positive numbers are not prime. Use trial division. Even numbers greater than 2 may be eliminated right away. A loop from 3 to √ n will suffice, but other loops are allowed.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Primality by trial division step by step in the zkl programming language
Source code in the zkl programming language
fcn isPrime(n){
if(n.isEven or n<2) return(n==2);
(not [3..n.toFloat().sqrt().toInt(),2].filter1('wrap(m){n%m==0}))
}
You may also check:How to resolve the algorithm Sorting algorithms/Selection sort step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Jewels and stones step by step in the Transd programming language
You may also check:How to resolve the algorithm Count occurrences of a substring step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Comments step by step in the X10 programming language
You may also check:How to resolve the algorithm Subtractive generator step by step in the C# programming language