Smallest square that begins with n: Difference between revisions

Add Factor
m (→‎{{header|Raku}}: Alternate)
(Add Factor)
Line 42:
3136 324 3364 3481 35344 36 3721 3844 3969 400
41209 4225 4356 441 45369 4624 4761 484 49
</pre>
 
=={{header|Factor}}==
{{trans|Phix}}
{{works with|Factor|0.99 2021-02-05}}
<lang factor>USING: arrays combinators.short-circuit.smart formatting io
kernel math sequences ;
 
[let
50 :> lim
lim 0 <array> :> res
1 0 :> ( n! found! )
[ found lim 1 - < ] [
n dup * :> n2!
[ n2 zero? ] [
{ [ n2 lim < ] [ n2 res nth zero? ] } &&
[ found 1 + found! n n2 res set-nth ] when
n2 10 /i n2!
] until
n 1 + n!
] while
res rest
]
 
"Smallest square that begins with..." print
[ 1 + swap [ sq ] keep "%2d: %5d (%3d^2)\n" printf ]
each-index</lang>
{{out}}
<pre style="height:20em">
Smallest square that begins with...
1: 1 ( 1^2)
2: 25 ( 5^2)
3: 36 ( 6^2)
4: 4 ( 2^2)
5: 529 ( 23^2)
6: 64 ( 8^2)
7: 729 ( 27^2)
8: 81 ( 9^2)
9: 9 ( 3^2)
10: 100 ( 10^2)
11: 1156 ( 34^2)
12: 121 ( 11^2)
13: 1369 ( 37^2)
14: 144 ( 12^2)
15: 1521 ( 39^2)
16: 16 ( 4^2)
17: 1764 ( 42^2)
18: 1849 ( 43^2)
19: 196 ( 14^2)
20: 2025 ( 45^2)
21: 2116 ( 46^2)
22: 225 ( 15^2)
23: 2304 ( 48^2)
24: 2401 ( 49^2)
25: 25 ( 5^2)
26: 2601 ( 51^2)
27: 2704 ( 52^2)
28: 289 ( 17^2)
29: 2916 ( 54^2)
30: 3025 ( 55^2)
31: 3136 ( 56^2)
32: 324 ( 18^2)
33: 3364 ( 58^2)
34: 3481 ( 59^2)
35: 35344 (188^2)
36: 36 ( 6^2)
37: 3721 ( 61^2)
38: 3844 ( 62^2)
39: 3969 ( 63^2)
40: 400 ( 20^2)
41: 41209 (203^2)
42: 4225 ( 65^2)
43: 4356 ( 66^2)
44: 441 ( 21^2)
45: 45369 (213^2)
46: 4624 ( 68^2)
47: 4761 ( 69^2)
48: 484 ( 22^2)
49: 49 ( 7^2)
</pre>
 
1,808

edits