2010年10月6日 星期三

Joseph Problem

'Joseph Problem
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim aL As New ArrayList
        Dim aLB As New ArrayList
        Dim aStr = "123456789ABCDE"
        For i = 1 To aStr.Length
            aL.Add(Mid(aStr, i, 1))
        Next
        Dim k = 3
        Dim ic = 0 + k - 1
        While aL.Count > 1
            ic = ic Mod aL.Count
            aLB.Add(aL.Item(ic))
            aL.RemoveAt(ic)
            ic = ic + k - 1
        End While
        MsgBox(aL.Item(0))
    End Sub
End Class

沒有留言: