Smallest square that begins with n: Difference between revisions

julia example
m (→‎{{header|Raku}}: self-ref: alternative haystack)
(julia example)
Line 101:
41209 4225 4356 441 45369 4624 4761 484 49
</pre>
 
=={{header|Julia}}==
<lang julia>function squaresstartingupto(n, verbose=true)
res, numfound = zeros(Int, n), 0
p_int = collect(1:n)
p_string = string.(p_int)
for i in 1:typemax(Int)
sq = i * i
sq_s = string(sq)
for (j, s) in enumerate(p_string)
if res[j] == 0 && length(sq_s) >= length(s) && sq_s[1:length(s)] == s
res[j] = sq
numfound += 1
end
end
if numfound == n
if verbose
for p in enumerate(res)
print(rpad(p[2], 6), p[1] % 10 == 0 ? "\n" : "")
end
end
break
end
end
return res
end
 
squaresstartingupto(49)
</lang>{{out}}
<pre>
1 25 36 4 529 64 729 81 9 100
1156 121 1369 144 1521 16 1764 1849 196 2025
2116 225 2304 2401 25 2601 2704 289 2916 3025
3136 324 3364 3481 35344 36 3721 3844 3969 400
41209 4225 4356 441 45369 4624 4761 484 49
</pre>
 
 
=={{header|Phix}}==
4,108

edits