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

Published on 12 May 2024 09:40 PM

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

Source code in the factor programming language

USING: kernel math math.functions math.ranges prettyprint
sequences ;

: non-sq ( n -- m ) dup sqrt 1/2 + floor + >integer ;

: print-first22 ( -- ) 22 [1,b] [ non-sq ] map . ;

: check-for-sq ( -- ) 1,000,000 [1,b)
    [ non-sq sqrt dup floor = [ "Square found." throw ] when ]
    each ;

print-first22 check-for-sq


  

You may also check:How to resolve the algorithm Square form factorization step by step in the Wren programming language
You may also check:How to resolve the algorithm Identity matrix step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm String case step by step in the 11l programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the Quackery programming language
You may also check:How to resolve the algorithm Knuth shuffle step by step in the R programming language