Best shuffle: Difference between revisions

Replaced VBScript implementation.
(Replaced VBScript implementation.)
Line 3,498:
 
=={{header|VBScript}}==
{{trans|Java}}
{{incorrect|VBScript|Abracadrabra should have a score of 0.}}
<lang vb>'Best Shuffle Task
Uses a random function as suggested in one of the discussion thread.
'VBScript Implementation
<lang vb>
 
Function shufflebestshuffle(s)
Dim arr()
ReDim Dim arr:Redim arr(Len(s)-1)
 
Set objrandom = CreateObject("System.Random")
'The Following Does the toCharArray() Functionality
For i = 1 To Len(s)
l For i = Mid0 To Len(s,i,1)-1
arr(i) = Mid(s, i + 1, 1)
Do
Next
n = objrandom.Next_2(0,Len(s))
 
If arr(n) = "" Then
arr = shuffler(arr) 'Comment this line for deterministic solution
arr(n) = l
For i = 0 To UBound(arr):Do
Exit Do
If arr(i) <> Mid(s, i + 1, 1) Then Exit Do
End If
For j = 10 To LenUBound(sarr)
Loop
If arr(i) <> arr(j) And arr(i) <> Mid(s, j + 1, 1) And arr(j) <> Mid(s, i + 1, 1) Then
Next
shuffled_word tmp = Join(arr,""(i)
arr(i) = arr(j)
score = 0
arr(j) = tmp
For j = 1 To Len(s)
End If
If Mid(s,j,1) = Mid(shuffled_word,j,1) Then
Next
score = score + 1
Loop While False:Next
End If
 
Next
shuffle = shuffled_word &= "Join(arr,(" & score & ")"
 
'This section is the scorer
score = 0
For ik = 1 To Len(s)
If Mid(s,jk,1) = Mid(shuffled_word,jk,1) Then
score = score + 1
End If
Next
 
bestshuffle = shuffled_word & ",(" & score & ")"
End Function
 
Function shuffler(array)
Set objrandomrand = CreateObject("System.Random")
For i = UBound(array) to 0 Step -1
r = rand.next_2(0, i + 1)
tmp = array(i)
array(i) = array(r)
array(r) = tmp
Next
shuffler = array
End Function
 
Line 3,528 ⟶ 3,549:
word_list = Array("abracadabra","seesaw","elk","grrrrrr","up","a")
For Each word In word_list
WScript.StdOut.WriteLine word & "," & shufflebestshuffle(word)
Next</lang>
</lang>
 
{{Out}}
<pre>abracadabra,aaacbrrbaadcaadbrabaar,(10)
<pre>
seesaw,essawe,(0)
abracadabra,aaacbrrbaad,(1)
seesawelk,aswesekel,(0)
elkgrrrrrr,klerrrrgrr,(15)
grrrrrr,rrrrrgr,(5)
up,pu,(0)
a,a,(1)</pre>
</pre>
 
=={{header|XPL0}}==
535

edits