Magic constant: Difference between revisions

Content added Content deleted
(→‎{{header|Factor}}: another six times faster, down to 340ms)
(julia example)
Line 141: Line 141:
10^20: 5848036
10^20: 5848036
</pre>
</pre>

=={{header|Julia}}==
Uses the inverse of the magic constant function for the last part of the task.
<lang julia>using Lazy

magic(x) = (1 + x^2) * x ÷ 2
magics = @>> Lazy.range() map(magic) filter(x -> x > 10) # first 2 values are filtered out
println("First 20 magic constants: ", Int.(take(20, magics)))
println("Thousandth magic constant is: ", collect(take(1000, magics))[end])

println("Smallest magic square with constant greater than:")
for expo in 1:20
goal = big"10"^expo
ordr = Int(floor((2 * goal)^(1/3))) + 1
println("10^", string(expo, pad=2), " ", ordr)
end
</lang>{{out}}
<pre>
First 20 magic constants: [15, 34, 65, 111, 175, 260, 369, 505, 671, 870, 1105, 1379, 1695, 2056, 2465, 2925, 3439, 4010, 4641, 5335]
Thousandth magic constant is: 503006505
Smallest magic square with constant greater than:
10^01 3
10^02 6
10^03 13
10^04 28
10^05 59
10^06 126
10^07 272
10^08 585
10^09 1260
10^10 2715
10^11 5849
10^12 12600
10^13 27145
10^14 58481
10^15 125993
10^16 271442
10^17 584804
10^18 1259922
10^19 2714418
10^20 5848036
</pre>



=={{header|Raku}}==
=={{header|Raku}}==