2009年4月15日 星期三

產生前十個 Conway數列項

image_thumb

'產生第一至十個 conway數列項
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim j
        Dim str2 = "1" & vbNewLine
        j = 2
        Dim t = 1
        While j <= 10
            str2 = str2 & conway(t) & vbNewLine
            t = conway(t)
            j = j + 1
        End While
        MsgBox(str2)
    End Sub
    Function conway(ByVal n)
        Dim i, c
        Dim str1 = ""
        i = 1
        c = 0
        While i <= n.ToString.Length
            c = c + 1
            '
            If Mid(n.ToString, i, 1) <> Mid(n.ToString, i + 1, 1) Then
                str1 = str1 & c & Mid(n.ToString, i, 1)
                c = 0
            End If
            i = i + 1
        End While
        conway = str1
    End Function
End Class

沒有留言: