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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sequence of non-squares step by step in the Forth 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 Forth programming language

Source code in the forth programming language

: u>f  0 d>f ;
: f>u  f>d drop ;

: fn ( n -- n ) dup u>f fsqrt fround f>u + ;
: test ( n -- ) 1 do i fn . loop ;
23 test    \ 2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27  ok

: square? ( n -- ? ) u>f fsqrt  fdup fround f-  f0= ;
: test ( n -- ) 1 do i fn square? if cr i . ." fn was square" then loop ;
1000000 test    \ ok


  

You may also check:How to resolve the algorithm Hickerson series of almost integers step by step in the C programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Visual Basic programming language
You may also check:How to resolve the algorithm Break OO privacy step by step in the J programming language
You may also check:How to resolve the algorithm A+B step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Fixed length records step by step in the Tcl programming language