Best shuffle: Difference between revisions
Replaced VBScript implementation.
Simple9371 (talk | contribs) (Replaced VBScript implementation.) |
|||
Line 3,498:
=={{header|VBScript}}==
{{trans|Java}}
<lang vb>'Best Shuffle Task
'VBScript Implementation
Function
Set objrandom = CreateObject("System.Random")▼
'The Following Does the toCharArray() Functionality
For i = 1 To Len(s)▼
arr(i) = Mid(s, i + 1, 1)
arr = shuffler(arr) 'Comment this line for deterministic solution
For i = 0 To UBound(arr):Do
If arr(i) <> Mid(s, i + 1, 1) Then Exit Do
End If▼
If arr(i) <> arr(j) And arr(i) <> Mid(s, j + 1, 1) And arr(j) <> Mid(s, i + 1, 1) Then
▲ Next
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
Next▼
'This section is the scorer
bestshuffle = shuffled_word & ",(" & score & ")"
End Function
Function shuffler(array)
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
Next</lang>
{{Out}}
seesaw,essawe,(0)
▲abracadabra,aaacbrrbaad,(1)
up,pu,(0)
a,a,(1)</pre>
=={{header|XPL0}}==
|