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
var order = ((goal * 2).cbrt).floor + 1
var power = BigInt.ten▼
// accuracy check as we're using Num arithmetic to calculate the order
var bigOrder = BigInt.new(order)
Fmt.print("10$-2s : $,9i", superscript.call(count), n)▼
if (!(magicConstant.call(bigOrder) > bigGoal && magicConstant.call(bigOrder-1) <= bigGoal)) {
}
}</lang>
|