How to resolve the algorithm Gaussian primes step by step in the Quackery programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Gaussian primes step by step in the Quackery programming language

Table of Contents

Problem Statement

A Gaussian Integer is a complex number such that its real and imaginary parts are both integers. The norm of a Gaussian integer is its product with its conjugate.

A Gaussian integer is a Gaussian prime if and only if either: both a and b are non-zero and its norm is a prime number, or, one of a or b is zero and it is the product of a unit (±1, ±i) and a prime integer of the form 4n + 3. Prime integers that are not of the form 4n + 3 can be factored into a Gaussian integer and its complex conjugate so are not a Gaussian prime. Gaussian primes are octogonally symmetrical on a real / imaginary Cartesian field. If a particular complex norm a² + b² is prime, since addition is commutative, b² + a² is also prime, as are the complex conjugates and negated instances of both.

Find and show, here on this page, the Gaussian primes with a norm of less than 100, (within a radius of 10 from the origin 0 + 0i on a complex plane.) Plot the points corresponding to the Gaussian primes on a Cartesian real / imaginary plane at least up to a radius of 50.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Gaussian primes step by step in the Quackery programming language

Source code in the quackery programming language

  [ $ "turtleduck.qky" loadfile ] now!

  [ ' [ 0 0 0 ] fill
      [ 12 5 circle ] ] is dot  (     -->   )

  [ 6 * 1 fly
    -1 4 turn
    6 * 1 fly
    1 4 turn ]          is toxy ( n n -->   )

  [ 2dup toxy
    dot
    1 2 turn
    toxy
    1 2 turn ]          is plot ( n n -->   )

  [ 4 times
      [ 300 1 walk
        -300 1 fly
        1 4 turn ] ]    is axes (     -->   )

  [ dup * ]             is ^2   (   n --> n )

  [ ^2 swap ^2 + ]      is norm ( n n --> n )

  4000 eratosthenes

  [ 2dup
    0 !=
    swap 0 != and iff
      [ norm isprime ]
      done
    + abs
    dup 4 mod 3 =
    swap isprime and ]  is gprime ( n n --> b )

  []
  20 ^2 1+ times
    [ i^ 20 /mod
      10 - dip [ 10 - ]
      2dup norm 10 ^2 > iff
        2drop done
      2dup gprime iff
        [ join
          nested join ]
      else 2drop ]
  [] swap
  witheach
    [ char [ swap
      2 times
      [ behead rot swap
          dup -1 > if
            [ swap space join
              swap ]
          number$ join
          swap ]
      drop
      char ] join
      nested join ]
  72 wrap$

  turtle
  0 frames
  axes
  100 ^2 1+ times
    [ i^ 100 /mod
      50 - dip [ 50 - ]
      2dup norm 50 ^2 > iff
        2drop done
      2dup gprime iff
        plot else 2drop ]
  1 frames

  

You may also check:How to resolve the algorithm McNuggets problem step by step in the Quackery programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Picat programming language
You may also check:How to resolve the algorithm 4-rings or 4-squares puzzle step by step in the Picat programming language
You may also check:How to resolve the algorithm Identity matrix step by step in the Forth programming language
You may also check:How to resolve the algorithm Sorting algorithms/Strand sort step by step in the Racket programming language