12? 1940 Stanislaw Ulam John von Neumann Cellular Automaton 2 Cellular Automata 1 0 1 2 0 1 A 3 B 1 2 3 C 10 A B C 1
ExcelVBA 1 1 1 1 0 1 1 B7 BD7 road1 B8 BD31 board 0 Road1 50 board 0 1 0 1 Excel 2 2
2 road1 10 0 1 road1 3 C4 AE4 8 0 1 VBEditor 3 1 3
6 1 Union myrange 1 Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) Dim myrange As Range Dim myret As Range Dim i As Integer Set myrange = Application.Union(Range("C4"), Range("G4"), _ Range("K4"), Range("O4"), Range("S4"), Range("W4"), _ Range("AA4"), Range("AE4"), Range("road1")) Set myret = Application.Intersect(Target, myrange) If Not myret Is Nothing Then Target.Value = 1 - Target.Value End If Cancel = True End Sub 1 Intersect Target myrange Nothing 1 0 1 Cancel True 2 2 2 2 myarr myarr(i) = Cells4,34*i.Value Rcnge("bocard").Value = 0 SR = Range("road1").Row:SC = Rcnge("roald1").Column CellCnt = Range("road1").ColulnnS.Count-1 4
Row Rows Column Columns '-------------------------------- ' 90 '------------------------------- Sub CellAuto() Dim i As Integer, j As Integer Dim SR As Integer, SC As Integer Dim CellCnt As Integer, ChkVal As Integer Dim BCol1 As Integer, BCol2 As Integer, BCol3 As Integer Dim myarr(7) As Integer Dim mystage As Integer ' mystage = Val(InputBox("225 ")) If mystage < 2 Or mystage > 25 Then MsgBox " ": Exit Sub End If ' For i = 0 To 7 myarr(i) = Cells(4, 3 + 4 * i).value Next ' Range("board").Value = 0 SR = Range("road1").Row: SC = Range("road1").Column CellCnt = Range("road1").Columns.Count - 1 ' For i = SR To SR + mystage - 2 For j = SC To SC + CellCnt - 2 BCol1 = Cells(i, j).value BCol2 = Cells(i, j + 1).Value BCol3 = Cells(i, j + 2).Value ' NO ChkVal = 4 * BCol1 + 2 * BCol2 + BCol3 ' Cells(i + 1, j + 1).Value = myarr(chkval) Next Next End Sub 5
Column SC Columns Range.Columns.Count Row Rows 2 8 3 000 111 8 1 000 0 1 001 010 1 2 101 3 2 2 2 2 011 4 1 1 2 0 101 5 110 6 111 7 2212101412015 3 BCol1 = Cells(i, i).value BCol2 = Cells(i, j + 1).Value BCol3 = Cells(i, j + 2).Value ' ChkVal = 4*BCol1 + 2 * BCol2 + BCol3 ChkVal myarr Cells(i + 1, j + 1).Value = myarr(chkval) 6
CellAuto 2 4 01011010 7 10 5 5 01011010 1 8 2 6 6 7
7 4 01011010 10100101 AC7 1 25 7 7 10100101 8
0101101010100101 8 3 0 1 2 2 8 256 0 1 01011010 010 01011010 90 90 2 2 1 1 0 2 9
8 8 9 A A 3 9 10 0 10 11 2 1 12 8 11 10111000 184 184 12 10
184 13 90 13 7 9 9 7 B7 BD7 board B9 BD9 road_work 0 01 7 0 1 3 1 3 Win32API Sleep 4 4 Sleep Declare Sleep 4 s_timewait 4 500 4 4 4 4 Copy Destination 11
4 10 3 Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) Dim myrange As Range Dim myret As Range Dim i As Integer Set myrange = Application.Union(Range("C4"), Range("G4"), _ Range("K4"), Range("O4"), Range("S4"), Range("W4"), _ Range("AA4"), Range("AE4"), Range("road2")) Set myret = Application.Intersect(Target, myrange) If Not myret Is Nothing Then If Target.Value = 0 Then Target.Value = 1 Else Target.Value = 0 End If End If Cancel = True End Sub 12
4 Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long) '-------------------------------- ' 184 '------------------------------- Sub Traffic() Dim i As Integer, j As Integer Dim SR As Integer, SC As Integer Dim CellCnt As Integer Dim ChkVal As Integer Dim BCol1 As Integer, BCol2 As Integer, BCol3 As Integer Dim myarr(7) As Integer ' For i = 0 To 7 myarr(i) = Cells(4, 3 + 4 * i).value Next ' Range("road_work").Value = 0 SR = Range("road2").Row: SC = Range("road2").Column CellCnt = Range("road2").Columns.Count - 1 ' For i = 1 To 10 For j = SC To SC + CellCnt - 2 BCol1 = Cells(SR, j).value BCol2 = Cells(SR, j + 1).Value BCol3 = Cells(SR, j + 2).Value ' NO ChkVal = 4 * BCol1 + 2 * BCol2 + BCol3 ' Select Case ChkVal Case 0 To 7 Cells(SR + 2, j + 1).Value = myarr(chkval) Case 8 To 14 Cells(SR + 2, j + 1).Value = myarr(chkval - 7) Case 10 To 21 Cells(SR + 2, j + 1).Value = 8 Case 32 To 33 Cells(SR + 2, j + 1).Value = myarr(chkval - 32) End Select Next s_timewait (500) ' Range(Cells(SR + 2, SC), Cells(SR + 2, SC + CellCnt)).Copy Destination:= _ Range(Cells(SR, SC), Cells(SR, SC + CellCnt)) Next End Sub '-------------------------------- ' s_timewait ' mymsec '-------------------------------- Sub s_timewait(mymsec As Long) DoEvents Sleep mymsec End Sub 13
14 Traffic 4 7 1 4 00011101 151 9 1 14 15 1 1 14
16 8 16 3 4 3 17 17 A 17 1 myarr (ChkVal-7) B 8 8 C 8 8 1 0 0 15
myarr (ChkVal-32) 10 3 1 1 2 3 1970 John Hoton Conway 2 16
17