Vampire number: Difference between revisions

Added Wren
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
(Added Wren)
Line 3,642:
14593825548650 is not a vampire number
</pre>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Math
import "/fmt" for Fmt
 
var ndigits = Fn.new { |x|
var n = 0
while (x > 0) {
n = n + 1
x = (x/10).floor
}
return n
}
 
var dtally = Fn.new { |x|
var t = 0
while (x > 0) {
t = t + 2.pow((x%10) * 6)
x = (x/10).floor
}
return t
}
 
var tens = List.filled(15, 0)
 
var init = Fn.new {
tens[0] = 1
for (i in 1..14) tens[i] = tens[i-1] * 10
}
 
var fangs = Fn.new { |x|
var f = []
var nd = ndigits.call(x)
if ((nd&1) == 1) return f
nd = (nd/2).floor
var lo = Math.max(tens[nd-1], ((x + tens[nd] -2) / (tens[nd] - 1)).floor)
var hi = Math.min((x/lo).floor, x.sqrt.floor)
var t = dtally.call(x)
var a = lo
while (a <= hi) {
var b = (x/a).floor
if (a*b == x && ((a%10) > 0 || (b%10) > 0) && t == dtally.call(a) + dtally.call(b)) {
f.add(a)
}
a = a + 1
}
return f
}
 
var showFangs = Fn.new { |x, f|
Fmt.write("$6d", x)
if (f.count > 1) System.print()
for (a in f) Fmt.print(" = $3d x $3d", a, (x/a).floor)
}
 
init.call()
var x = 1
var n = 0
while (n < 25) {
var f = fangs.call(x)
if (f.count > 0) {
n = n + 1
Fmt.write("$2d: ", n)
showFangs.call(x, f)
}
x = x + 1
}
System.print()
for (x in [16758243290880, 24959017348650, 14593825548650]) {
var f = fangs.call(x)
if (f.count > 0) {
showFangs.call(x, f)
} else {
Fmt.print("$d is not vampiric", x)
}
}</lang>
 
{{out}}
<pre>
1: 1260 = 21 x 60
2: 1395 = 15 x 93
3: 1435 = 35 x 41
4: 1530 = 30 x 51
5: 1827 = 21 x 87
6: 2187 = 27 x 81
7: 6880 = 80 x 86
8: 102510 = 201 x 510
9: 104260 = 260 x 401
10: 105210 = 210 x 501
11: 105264 = 204 x 516
12: 105750 = 150 x 705
13: 108135 = 135 x 801
14: 110758 = 158 x 701
15: 115672 = 152 x 761
16: 116725 = 161 x 725
17: 117067 = 167 x 701
18: 118440 = 141 x 840
19: 120600 = 201 x 600
20: 123354 = 231 x 534
21: 124483 = 281 x 443
22: 125248 = 152 x 824
23: 125433 = 231 x 543
24: 125460
= 204 x 615
= 246 x 510
25: 125500 = 251 x 500
 
16758243290880
= 1982736 x 8452080
= 2123856 x 7890480
= 2751840 x 6089832
= 2817360 x 5948208
24959017348650
= 2947050 x 8469153
= 2949705 x 8461530
= 4125870 x 6049395
= 4129587 x 6043950
= 4230765 x 5899410
14593825548650 is not vampiric
</pre>
 
 
=={{header|zkl}}==
9,488

edits