How to resolve the algorithm Primality by Wilson's theorem step by step in the Arturo programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Primality by Wilson's theorem step by step in the Arturo programming language

Table of Contents

Problem Statement

Write a boolean function that tells whether a given integer is prime using Wilson's theorem. By Wilson's theorem, a number p is prime if and only if p divides (p - 1)! + 1. Remember that 1 and all non-positive integers are not prime.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Primality by Wilson's theorem step by step in the Arturo programming language

Source code in the arturo programming language

factorial: function [x]-> product 1..x

wprime?: function [n][
    if n < 2 -> return false
    zero? mod add factorial sub n 1 1 n
]

print "Primes below 20 via Wilson's theorem:"
print select 1..20 => wprime?


  

You may also check:How to resolve the algorithm Arbitrary-precision integers (included) step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm File modification time step by step in the Erlang programming language
You may also check:How to resolve the algorithm Rename a file step by step in the Forth programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the UnixPipes programming language
You may also check:How to resolve the algorithm Draw a sphere step by step in the V (Vlang) programming language