Showing posts with label Rotation Count. Show all posts
Showing posts with label Rotation Count. Show all posts

Wednesday, February 6, 2013

Rotate Array, check for a match & rotation count

Function ArraymatchCheck

'Two arrays that need to be checked

A= Array(1,2,3,4)
B= Array(1,2,3,4)
count1=0
ordrr=false
C=join(A)
E=join(B)

'Check whether two matches at first
if Eval(C=E) then
ordrr=true
msgbox "It taken "&count1&" rotations to get the match",,"Rotation Count"
Exit Function
end if

'Do rotation & Check for match
Do until Ordrr= true
temp1=B(0)
B(0)=B(1)
B(1)=B(2)
B(2)=B(3)
B(3)=temp1
C=join(A)
D=join(B)
count1=count1+1

If Eval(D=E) Then
    msgbox "Match cannot be made",,"Warning"
    Exit Do
End If
if Eval(C=D) then
ordrr=true
msgbox "It taken "&count1&" rotations to get the match",,"Rotation Count"
Exit do
end if
loop

End Function

ArraymatchCheck