How to resolve the algorithm Wilson primes of order n step by step in the jq programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Wilson primes of order n step by step in the jq programming language
Table of Contents
Problem Statement
A Wilson prime of order n is a prime number p such that p2 exactly divides:
If n is 1, the latter formula reduces to the more familiar: (p - n)! + 1 where the only known examples for p are 5, 13, and 563.
Calculate and show on this page the Wilson primes, if any, for orders n = 1 to 11 inclusive and for primes p < 18 or, if your language supports big integers, for p < 11,000.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Wilson primes of order n step by step in the jq programming language
Source code in the jq programming language
def emit_until(cond; stream): label $out | stream | if cond then break $out else . end;
# For 0 <= $n <= ., factorials[$n] is $n !
def factorials:
reduce range(1; .+1) as $n ([1];
.[$n] = $n * .[$n-1]);
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
def primes: 2, (range(3; infinite; 2) | select(is_prime));
# Input: the limit of $p
def wilson_primes:
def sgn: if . % 2 == 0 then 1 else -1 end;
. as $limit
| factorials as $facts
| " n: Wilson primes\n--------------------",
(range(1;12) as $n
| "\($n|lpad(2)) : \(
[emit_until( . >= $limit; primes)
| select(. as $p
| $p >= $n and
(($facts[$n - 1] * $facts[$p - $n] - ($n|sgn))
% ($p*$p) == 0 )) ])" );
11000 | wilson_primes
You may also check:How to resolve the algorithm Radical of an integer step by step in the RPL programming language
You may also check:How to resolve the algorithm Loops/Downward for step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the VBA programming language
You may also check:How to resolve the algorithm Cut a rectangle step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Loops/Wrong ranges step by step in the C programming language