Magic constant: Difference between revisions

→‎{{header|Wren}}: Updated version - now almost instant (13 ms).
(julia example)
(→‎{{header|Wren}}: Updated version - now almost instant (13 ms).)
Line 226:
{{libheader|Wren-fmt}}
{{libheader|Wren-big}}
This uses Julia's approach for the final parts though, as our BigInt class doesn't have a cube root function, we use Num (i.e. double precision floating point) arithmetic instead and then check that the answers are correct.
<lang ecmascript>import "./seq" for Lst
import "./fmt" for Fmt
Line 244 ⟶ 245:
 
System.print("\nSmallest order magic square with a constant greater than:")
for (i in 1..20) {
var count = 1
var ngoal = BigInt10.threepow(i)
var order = ((goal * 2).cbrt).floor + 1
var power = BigInt.ten
// accuracy check as we're using Num arithmetic to calculate the order
while (count <= 20) {
var powerbigGoal = BigInt.ten.pow(i)
if (magicConstant.call(n) > power) {
var bigOrder = BigInt.new(order)
Fmt.print("10$-2s : $,9i", superscript.call(count), n)
if (!(magicConstant.call(bigOrder) > bigGoal && magicConstant.call(bigOrder-1) <= bigGoal)) {
power = power * 10
countSystem.print("Order =for count10^%(i) +is 1inaccurate.")
}
Fmt.print("10$-2s : $,9i", superscript.call(counti), norder)
n = n.inc
}</lang>
 
9,477

edits