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.




#lang transd
 
MainModule: {
    nonsqr: (λ i Int()
    	(ret (+ i (to-Int (floor (+ 0.5 (sqrt i))))))),
 
    _start: (lambda locals: d Double()
        (for i in Range(1 23) do
            (textout (nonsqr i) " "))
 
        (for i in Range(1 1000001) do
            (= d (sqrt (nonsqr i)))
            (if (eq d (floor d)) 
                (throw String("Square: " i))))
 
        (textout "\n\nUp to 1 000 000 - no squares found.")
    )
}