math, primes : Wilson theorem

Share your advanced PureBasic knowledge/code with the community.
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

math, primes : Wilson theorem

Post by Olli »

Code to understand this crazy rule :

Code: Select all

Dim s.s(1)
s(0) = " = 0 so it's a prime"
fact + 1
Debug Chr($8000)
For n = 2 To 21
   Debug Rset(Str(fact + 1), 24, " ") + "+1  % " + Str(n) + s(Bool((fact + 1) % n) )
   fact * n
Next
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: math, primes : Wilson theorem

Post by Olli »

Code: Select all

Procedure isPrime(p)
   Protected a = p - 1
   Protected b
   For i = p - 2 To 2 Step -1
      a * i
      a % p
   Next
   a + 1
   ProcedureReturn Bool(a = p)
EndProcedure
Post Reply