Duffinian numbers: Difference between revisions

Content added Content deleted
(→‎{{header|Wren}}: Now uses Fmt.tprint and new Int.divisorSum method - 3 times faster than before.)
Line 1,030: Line 1,030:
{{libheader|Wren-seq}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
<syntaxhighlight lang="ecmascript">import "./math" for Int
import "./seq" for Lst
import "./seq" for Lst
import "./fmt" for Fmt
import "./fmt" for Fmt
Line 1,043: Line 1,043:
continue
continue
}
}
var sigmaSum = Nums.sum(Int.divisors(i))
var sigmaSum = Int.divisorSum(i)
if (Int.gcd(sigmaSum, i) != 1) d[i] = false
if (Int.gcd(sigmaSum, i) != 1) d[i] = false
}
}
Line 1,049: Line 1,049:
var duff = (1...d.count).where { |i| d[i] }.toList
var duff = (1...d.count).where { |i| d[i] }.toList
System.print("First 50 Duffinian numbers:")
System.print("First 50 Duffinian numbers:")
for (chunk in Lst.chunks(duff[0..49], 10)) Fmt.print("$3d", chunk)
Fmt.tprint("$3d", duff[0..49], 10)


var triplets = []
var triplets = []
Line 1,056: Line 1,056:
}
}
System.print("\nFirst 50 Duffinian triplets:")
System.print("\nFirst 50 Duffinian triplets:")
for (chunk in Lst.chunks(triplets[0..49], 4)) Fmt.print("$-25s", chunk)</syntaxhighlight>
Fmt.tprint("$-25n", triplets[0..49], 4)</syntaxhighlight>


{{out}}
{{out}}