Boolean Gray Code

Public Function GraySeq(ByVal N As Long) As String()

  ReDim ret(0 To 2 ^ N 1) As String

 

  If N = 1 Then

    ret(0) = "0": ret(1) = "1"

  ElseIf N > 1 Then

    Dim prev() As String: prev =
GraySeq(N
1)

    Dim Ix As Long

    For Ix = 0 To 2 ^ (N 1) 1

      ret(Ix) = "0" &
prev(Ix)

      ret(2 ^ (N)
1 Ix) = "1" &
prev(Ix)

    Next

  Else

    Err.Raise &H80070057, , "Invalid Parameter"

  End If

 

  GraySeq = ret

End Function

Advertisements
This entry was posted in Kategorizálatlan. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s