Task

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

            n + floor(1/2 + sqrt(n)) 

 Print out the values for    n    in the range   1   to   22
 Show that no squares occur for    n    less than one million


This is sequence   A000037   in the OEIS database.




| nonSquare isSquare squaresFound |
nonSquare := [:n |
    n + (n sqrt) rounded
].
isSquare := [:n |
    n = (((n sqrt) asInteger) raisedTo: 2)
].
Transcript show: 'The first few non-squares:'; cr.
1 to: 22 do: [:n |
    Transcript show: (nonSquare value: n) asString; cr
].
squaresFound := 0.
1 to: 1000000 do: [:n |
    (isSquare value: (nonSquare value: n)) ifTrue: [
        squaresFound := squaresFound + 1
    ]
].
Transcript show: 'Squares found for values up to 1,000,000: ';
show: squaresFound asString; cr