Sequence of non-squares: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add SETL) |
(Added Chipmunk Basic) |
||
Line 527: | Line 527: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{ out }} |
{{ out }} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27 |
2 3 5 6 7 8 10 11 12 13 14 15 17 18 19 20 21 22 23 24 26 27 |
||
Number of squares less than 1'000'000 produced by the formula: 0 |
Number of squares less than 1'000'000 produced by the formula: 0</pre> |
||
</pre> |
|||
=={{header| |
=={{header|Chipmunk Basic}}== |
||
{{trans|BASIC256}} |
|||
{{works with|Chipmunk Basic|3.6.4}} |
|||
<syntaxhighlight lang="basic">10 rem Sequence of non-squares |
|||
20 cls |
|||
30 ' Display first 22 values |
|||
40 for i = 1 to 22 |
|||
50 print nonsqr(i) " "; |
|||
60 next i |
|||
70 print |
|||
80 ' Check for squares up to one million |
|||
90 found = 0 |
|||
100 for i = 1 to 1000000 |
|||
110 j = sqr(nonsqr(i)) |
|||
120 if j = int(j) then |
|||
130 found = 1 |
|||
140 print "Found square: " i |
|||
150 exit for |
|||
160 endif |
|||
170 next i |
|||
180 if found = 0 then print "No squares occur for n < 1000000" |
|||
190 end |
|||
200 sub nonsqr(n) |
|||
210 nonsqr = n+int(0.5+sqr(n)) |
|||
220 return</syntaxhighlight> |
|||
=={{header|Clojure}}== |
|||
<syntaxhighlight lang="clojure">;; provides floor and sqrt, but we use Java's sqrt as it's faster |
<syntaxhighlight lang="clojure">;; provides floor and sqrt, but we use Java's sqrt as it's faster |
||
;; (Clojure's is more exact) |
;; (Clojure's is more exact) |