Vorige Pagina About the Author

' Constructs 6 x 6 Generators with 6 Magic Rows
' Consecutive Prime Numbers

' Tested with Office 2007 under Windows 7

Sub CnstrGen01()

Dim a(36), a1(36), a2(36), nRw(6)

y = MsgBox("Blocked", vbInformation, "CnstrGen01")
End

Sheets("Klad1").Select

n1 = 0: n9 = 0: k1 = 1: k2 = 1

n0 = 2: n8 = 12981: n81 = 1946
ShtNm1 = "MgcLns6"

For j1 = 2 To n81 
Chk1 = Sheets(ShtNm1).Cells(j1, 8).Value: If Chk1 = 1 Then GoTo 10
Cells(k1 + 1, 1).Select: Cells(k1 + 1, 1).Value = j1

    n10 = 6: Erase a
    For i1 = 1 To 6
        a1(i1) = Sheets(ShtNm1).Cells(j1, i1).Value
    Next i1
    nRw(1) = j1
    
    For i1 = 1 To 6             'First Line
        a(i1) = a1(i1)
    Next i1
    
    GoSub 200                   'Remainder of Lines
    
    n9 = n9 + 1: GoSub 650      'Print results (squares)
'   End

   n10 = n10 - 6
10 Next j1

End

200

For j2 = n81 + 1 To n8
Chk1 = Sheets(ShtNm1).Cells(j2, 8).Value: If Chk1 = 1 Then GoTo 20
j100 = j2: j101 = 2: GoSub 100: If fl1 = 0 Then GoTo 20
nRw(2) = j2

For j3 = j2 + 1 To n8
Chk1 = Sheets(ShtNm1).Cells(j3, 8).Value: If Chk1 = 1 Then GoTo 30
j100 = j3: j101 = 3: GoSub 100: If fl1 = 0 Then GoTo 30
nRw(3) = j3

For j4 = j3 + 1 To n8
Chk1 = Sheets(ShtNm1).Cells(j4, 8).Value: If Chk1 = 1 Then GoTo 40
j100 = j4: j101 = 4: GoSub 100: If fl1 = 0 Then GoTo 40
nRw(4) = j4

For j5 = j4 + 1 To n8
Chk1 = Sheets(ShtNm1).Cells(j5, 8).Value: If Chk1 = 1 Then GoTo 50
j100 = j5: j101 = 5: GoSub 100: If fl1 = 0 Then GoTo 50
nRw(5) = j5

For j6 = j5 + 1 To n8
Chk1 = Sheets(ShtNm1).Cells(j6, 8).Value: If Chk1 = 1 Then GoTo 60
j100 = j6: j101 = 6: GoSub 100: If fl1 = 0 Then GoTo 60
nRw(6) = j6

   Return

   n10 = n10 - 6
60 Next j6
   n10 = n10 - 6
50 Next j5
   n10 = n10 - 6
40 Next j4
   n10 = n10 - 6
30 Next j3
   n10 = n10 - 6
20 Next j2

    Return

100 fl1 = 1

    For i1 = 1 To 6
        a2(i1) = Sheets(ShtNm1).Cells(j100, i1).Value
    Next i1

    For i1 = 1 To 6
    a20 = a2(i1)
    For i2 = 1 To n10
        If a20 = a(i2) Then fl1 = 0: Return
    Next i2
    Next i1
    
    n10 = n10 + 6
    i2 = 0
    For i1 = n10 - 6 + 1 To n10
        i2 = i2 + 1
        a(i1) = a2(i2)
    Next i1

Return

'   Print Results (Squares)

650 n2 = n2 + 1
    If n2 = 5 Then
        n2 = 1: k1 = k1 + 7: k2 = 1
    Else
        If n9 > 1 Then k2 = k2 + 7
    End If

    Cells(k1, k2 + 1).Select
    Cells(k1, k2 + 1).Font.Color = -4165632
    Cells(k1, k2 + 1).Value = n9
    
    i3 = 0
    For i1 = 1 To 6
        For i2 = 1 To 6
            i3 = i3 + 1
            Cells(k1 + i1, k2 + i2).Value = a(i3)
        Next i2

'       Row Number
        Cells(k1 + i1, k2 + 7).Value = nRw(i1)
'       Sheets(ShtNm1).Cells(nRw(i1), 8).Value = 1  'Mark Used Row (Option)
        
    Next i1
   
    Return

End Sub

Vorige Pagina About the Author