Smallest square that begins with n: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: use pow10)
Line 1,783: Line 1,783:


=={{header|Julia}}==
=={{header|Julia}}==
<syntaxhighlight lang="julia">function squaresstartingupto(n, verbose=true)
<syntaxhighlight lang="julia">function smsq(n = 49)
res, numfound = zeros(Int, n), 0
results = zeros(Int, n)
p_int = collect(1:n)
found, square, delta = 0, 1, 3
while found < n
p_string = string.(p_int)
for i in 1:typemax(Int)
k = square
sq = i * i
while k > 0
sq_s = string(sq)
if k <= n && results[k] == 0
for (j, s) in enumerate(p_string)
results[k] = square
if res[j] == 0 && length(sq_s) >= length(s) && sq_s[1:length(s)] == s
found += 1
res[j] = sq
numfound += 1
end
end
k ÷= 10
end
end
if numfound == n
square += delta
if verbose
delta += 2
for p in enumerate(res)
print(rpad(p[2], 6), p[1] % 10 == 0 ? "\n" : "")
end
end
break
end
end
end
return res
return results
end
end


foreach(p -> print(rpad(p[2], 6), p[1] % 10 == 0 ? "\n" : ""), enumerate(smsq()))
squaresstartingupto(49)
</syntaxhighlight>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>