Jump to content

Best shuffle: Difference between revisions

no edit summary
No edit summary
Line 3,070:
original: up new: pu count: 0
original: a new: a count: 1
</pre>
 
=={{header|Ring}}==
<lang ring>
# Project : Best shuffle
# Date : 2018/02/15
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.com>
 
test = ["abracadabra", "seesaw", "elk", "grrrrrr", "up", "a"]
 
for n = 1 to len(test)
bs = bestshuffle(test[n])
count = 0
for p = 1 to len(test[n])
if substr(test[n],p,1) = substr(bs,p,1)
count = count + 1
ok
next
see test[n] + " -> " + bs + " " + count + nl
next
func bestshuffle(s1)
s2 = s1
for i = 1 to len(s2)
for j = 1 to len(s2)
if (i != j) and (s2[i] != s1[j]) and (s2[j] != s1[i])
if j < i
i1 = j
j1 = i
else
i1 = i
j1 = j
ok
s2 = left(s2,i1-1) + substr(s2,j1,1) + substr(s2,i1+1,(j1-i1)-1) + substr(s2,i1,1) + substr(s2,j1+1)
ok
next
next
bestshuffle = s2
return s2 # bestshuffle
</lang>
Output:
<pre>
abracadabra -> caadrbabaar 0
seesaw -> ewaess 0
elk -> kel 0
grrrrrr -> rgrrrrr 5
up -> pu 0
a -> a 1
</pre>
 
2,468

edits

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