How to resolve the algorithm Sequence of non-squares step by step in the MAD programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sequence of non-squares step by step in the MAD programming language

Table of Contents

Problem Statement

Show that the following remarkable formula gives the sequence of non-square natural numbers:

This is sequence   A000037   in the OEIS database.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sequence of non-squares step by step in the MAD programming language

Source code in the mad programming language

            NORMAL MODE IS INTEGER
            BOOLEAN FOUND
            FOUND = 0B
         
          R SEQUENCE OF NON-SQUARES FORMULA
          R FLOOR IS AUTOMATIC DUE TO INTEGER MATH
            INTERNAL FUNCTION NONSQR.(N) = N+(.5+SQRT.(N))
            
          R PRINT VALUES FOR 1..N..22            
            THROUGH SHOW, FOR N=1, 1, N.G.22
SHOW        PRINT FORMAT OUTFMT,N,NONSQR.(N)
            VECTOR VALUES OUTFMT = $I2,2H: ,I2*$

          R CHECK FOR NO SQUARES UP TO ONE MILLION
            THROUGH CHECK, FOR N=1, 1, N.GE.1000000
            X=NONSQR.(N)
            Y=SQRT.(X)
            WHENEVER Y*Y.E.X
                PRINT FORMAT FINDSQ,N,X
                FOUND = 1B 
CHECK       END OF CONDITIONAL
            WHENEVER .NOT. FOUND, PRINT FORMAT NOSQ
            
            VECTOR VALUES FINDSQ = $5HELEM ,I5,2H, ,I5,11H, IS SQUARE*$ 
            VECTOR VALUES NOSQ = $16HNO SQUARES FOUND*$
            END OF PROGRAM

  

You may also check:How to resolve the algorithm Scope modifiers step by step in the E programming language
You may also check:How to resolve the algorithm Function composition step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the ZX Spectrum Basic programming language
You may also check:How to resolve the algorithm Galton box animation step by step in the Clojure programming language
You may also check:How to resolve the algorithm Sorting algorithms/Heapsort step by step in the PL/I programming language