Jump to content

Factorions: Difference between revisions

Added Wren
m (→‎{{header|Perl}}: Fix link: Perl 6 --> Raku)
(Added Wren)
Line 620:
The factorions for base 12 are:
1 2</pre>
 
=={{header|Wren}}==
{{trans|Go}}
<lang ecmascript>var digits = "0123456789abcdefghijklmnopqrstuvwxyz"
 
// Converts an integer to a string in a given base.
var intToString = Fn.new { |n, b|
if (!n.isInteger) return null
if (b < 2 || b > 36) return null // invalid base
if (n == 0) return "0"
var l = []
var neg = (n < 0)
if (neg) n = -n
var d = digits[0...b] // allowable digits for this base
while (n > 0) {
var r = n % b
l.add("%(d[r])")
n = (n/b).floor
}
if (neg) l.add("-")
var s = l.join()
return s[-1..0]
}
 
// cache factorials from 0 to 11
var fact = List.filled(12, 0)
fact[0] = 1
for (n in 1..11) fact[n] = fact[n-1] * n
 
for (b in 9..12) {
System.print("The factorions for base %(b) are:")
for (i in 1...1500000) {
var digs = intToString.call(i, b)
var sum = 0
for (d in digs) {
var n = d.codePoints[0]
if (n < 97) {
sum = sum + fact[n - 48]
} else {
sum = sum + fact[n - 87]
}
}
if (sum == i) System.write("%(i) ")
}
System.print("\n")
}</lang>
 
{{out}}
<pre>
The factorions for base 9 are:
1 2 41282
 
The factorions for base 10 are:
1 2 145 40585
 
The factorions for base 11 are:
1 2 26 48 40472
 
The factorions for base 12 are:
1 2
</pre>
 
=={{header|zkl}}==
9,492

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.