Vampire number: Difference between revisions

Content added Content deleted
No edit summary
Line 2,759: Line 2,759:
<pre>
<pre>
14593825548650 isn't a vampire number.
14593825548650 isn't a vampire number.
</pre>

=={{header|Ring}}==
<lang ring>
# Project : Vampire number
# Date : 2018/02/01
# Author : Gal Zsolt [~ CalmoSoft ~]
# Email : <calmosoft@gmail.com>

for p = 10 to 127000
vampire(p)
next

func vampire(listnum)
sum = 0
flag = 1
list = list(len(string(listnum)))
total = newlist(len(list),2)
for n = 1 to len(string(listnum))
liststr = string(listnum)
list[n] = liststr[n]
next

for perm = 1 to fact(len(list))
numstr = substr(list2str(list), nl, "")
num1 = number(left(numstr,len(numstr)/2))
num2 = number(right(numstr,len(numstr)/2))
if (listnum = num1 * num2)
for n = 1 to len(total)
if (num1 = total[n][2] and num2 = total[n][1]) or
(num1 = total[n][1] and num2 = total[n][2])
flag = 0
ok
next
if flag = 1
sum = sum + 1
total[sum][1] = num1
total[sum][2] = num2
see "" + listnum + ": [" + num1 + "," + num2 + "]" + nl
ok
ok
nextPermutation(list)
next
func nextPermutation(a)
elementcount = len(a)
if elementcount < 1 then return ok
pos = elementcount-1
while a[pos] >= a[pos+1]
pos -= 1
if pos <= 0 permutationReverse(a, 1, elementcount)
return ok
end
last = elementcount
while a[last] <= a[pos]
last -= 1
end
temp = a[pos]
a[pos] = a[last]
a[last] = temp
permutationReverse(a, pos+1, elementcount)
func permutationReverse a, first, last
while first < last
temp = a[first]
a[first] = a[last]
a[last] = temp
first += 1
last -= 1
end

func fact(nr)
if nr = 1
return 1
else
return nr * fact(nr-1)
ok

func newlist(x,y)
if isstring(x) x=0+x ok
if isstring(y) y=0+y ok
alist = list(x)
for t in alist
t = list(y)
next
return alist
</lang>
Output:
<pre>
1260: [21,60]
1395: [15,93]
1435: [35,41]
1530: [30,51]
1827: [21,87]
2187: [27,81]
6880: [80,86]
102510: [201,510]
104260: [260,401]
105210: [210,501]
105264: [204,516]
105750: [150,705]
108135: [135,801]
110758: [158,701]
115672: [152,761]
116725: [161,725]
117067: [167,701]
118440: [141,840]
123354: [231,534]
124483: [281,443]
125248: [152,824]
125433: [231,543]
125460: [204,615]
[246,510]
125500: [251,500]
126027: [201,627]
</pre>
</pre>