Results 1 to 18 of 18

Thread: Magic Squares

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    2

    Magic Squares

    Recentallly i was doing a programming competition and this was one of the questions:


    Task 4 - Balanced Squares
    Description
    9 numbers arranged in a 3x3 square is said to form a Balanced Square if every row and every column has the same sum.

    For example

    1 8 6
    10 5 0
    4 2 9

    is a Balanced Square as every row and column add up to 15.
    1 2 3
    3 1 2
    2 3 1

    is also a Balanced Square, every row and column add up to 6.
    Write a program which, given a list of 9 integers, prints them out in a Balanced Square. If the integers can be arranged into a Balanced Square in more than one way you may print whichever one you wish.

    If it is not possible to form a Balanced Square using the integers print out a message stating this.

    The format of your output should match the examples below:

    Sample Output
    Input
    0 1 2 4 6 8 5 10 9
    Output
    1 8 6
    10 5 0
    4 2 9

    Input
    1 1 1 2 2 2 3 3 3
    Output
    1 2 3
    3 1 2
    2 3 1

    Input
    0 1 2 4 6 8 5 3 9
    Output
    0 1 2 4 6 8 5 3 9 cannot be made into a Balanced Square.


    Test Data
    0 1 2 4 6 8 5 10 9
    1 1 1 2 2 2 3 3 3
    0 1 2 4 6 8 5 3 9
    1 2 3 4 5 6 7 8 9
    12 1 2 3 4 5 6 7 8
    1 2 3 3 6 7 4 5 5
    8 2 7 1 4 3 3 6 2

    Constraints
    You may assume the integers are not negative.

    It was the only question that I couldn't successfully complete, or even work out any way to even start it! All i could think of was to do a pure number crunch, but surly theres a better way! Any suggestions?

  2. #2
    Lively Member
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    89
    You can simplify your search by solving sets of simultaneous equations.

    a + b + c = x
    d + e + f = x
    g + h + i = x

    therefore a+b+c+d+e+f+g+h+i = 3x

    the first one is to determine what is an x you can see that it is sum of all numbers devided by 3

    following the same theory you can do the task. I would not recomend to use VB for the task. I is not going to be very quick.

    I would recomend to use eclipse, if you have a choice. The other option is c/c++, you have to be very good to do it.
    http://www.icparc.ic.ac.uk/eclipse/

    Search internet for "constraint satisfaction and optimisation"

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    This is an interesting one
    I'll see if I can piece something together .....
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    I think this does it. I’m not sure it is the most efficient way of getting there but it does seem to work. It can take some time for it to check all possible combinations. It appears there are about 36000 unique combinations that can be generated from 9 numbers.

    It is not in the format shown but that could be easily changed.

    By using klintsovi suggestion, you could avoid unnecessary checking.

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    This may be of benefit :

    http://www.math.twsu.edu/history/Act...html#magic-act


    ... btw, I hate number theory
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    For each combination of 9 integers there is 362880 permutations.

    It took my PIII 5 mins just to run through all the permutations, and I haven't included the magic squares test.

    However, I don't see what stops you from writing it in VB except that it will be slower than other lower level languages.

  7. #7
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Bah!

    We dont want number crunching.
    We want a smart way of doing it.


    Though. Now that I come to think of it,
    a number crunch application would be a great thing to put in a test. I dont think that a programming exam would test you on some obscure theorem ....
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    2
    How would anyone have time to write all those if statements in a 2 hr comp? Now that I've seen a solution i understand a bit on how to do it. Thanks for the help!

  9. #9
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I just thought of something.


    Lets say you have a 3x3 square.
    There are 8 lines that have to add up correctly.

    So I *think* I would be right in saying, that if you were to number crunch the combinations of numbers, and once you hit your 8th different permutation, you must have a magic square.

    A general case then would be that you require (Number of squares - 1) different permutations of the numbers that add up the same to have a magic square.


    Is this correct, or am I making some false assumptions ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  10. #10
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    You're a bit hung up on what a permutation really is. For a set of N numbers, the value you get when you do a permutation calculation on N is the total number of different ways to arrange the N numbers where order is important, meaning that for N=3, 123 is considered distinct from 321. In a combination (the counterpart of a permutation), the order of the set is not considered important, and thus 123 and 321 are treated as the same set of numbers even though they have a different order. There's also two things mentioned here, a balanced square (which I've never actually heard described mathematically but that doesn't mean it's not real), and the magic square which I'm familiar with. The page mentioned deals with magic squares only, and there are certain requirements for the numbers, like cardinal order from 1 to N^2. If you went by the 8 distinct permutation rule though, nothing is really holding you to the constraint of having a "magic square" (or the balanced one) when you see the 8th different permutation, as all permutation sets are considered different from each other. If that doesn't make sense, look at this generalization (as if you have such a belief you want to test, it will have to hold up to any generalization you give it). Take this set of numbers 1, 1, 1, 1, 1, 1, 1, 1, 2 for a 3x3 square. According to the balanced square data entry, that would be allowable. There are at least 9 different orders, but you can't make a balanced square from that set, since any row or column that contains the 2 will be off.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  11. #11
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Originally posted by TGR
    How would anyone have time to write all those if statements in a 2 hr comp? Now that I've seen a solution i understand a bit on how to do it. Thanks for the help!
    If you use a recursive function, you don't have to write much code at all.

    Here is a general solution that calculates all permutations for any number of inputs:

    VB Code:
    1. Sub Permutations(s As String, Optional sleading As String)
    2.  ' Nucleus
    3.  Dim i          As Long
    4.  Dim a          As Variant
    5.  
    6.  a = Split(s, ",")
    7.  For i = 0 To UBound(a)
    8.     If UBound(a) > 1 Then
    9.         Permutations Right$(s, Len(s) - InStr(1, s, ",")), IIf(Len(sleading), sleading & "," & Left$(s, InStr(1, s, ",") - 1), Left$(s, InStr(1, s, ",") - 1))
    10.     Else
    11.         Debug.Print sleading & "," & s
    12.     End If
    13.    
    14.     s = Right$(s, Len(s) - InStr(1, s, ",")) & "," & Left$(s, InStr(1, s, ",") - 1)
    15.  Next
    16. End Sub

    To use the function pass csv input values and the function does the rest. Output is to the debug window.

    For example to calculate all permutations for 1 2 10?
    VB Code:
    1. Call Permutations("1,2,10")

  12. #12
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    I knew there had to be a cleaner way. I just never really got a handle on recurssion. This is really cool.

  13. #13
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930

    Math haters please ignore this... you've been warned ;)

    In case anyone wants them, here's some stuff relating to this whole discussion.
    VB Code:
    1. 'in a module
    2.  
    3. 'returns n!, by a recursive style (just in case anyone not familiar with recursion wants to see how it's done.  recursion should be avoided if possible though
    4. Public Function RFactorial(ByVal n As Long) As Double
    5.    RFactorial = 1
    6.    If n < 1 Then Exit Function
    7.    If n = 1 Then
    8.       RFactorial = 1
    9.    Else
    10.       RFactorial = n * RFactorial(n - 1)
    11.    End If
    12. End Function
    13.  
    14. 'returns n! as well, but by an iterative method
    15. Public Function Factorial(ByVal n As Long) As Double
    16.    Factorial = 1
    17.    If n = 1 Then Exit Function
    18.    Do While n > 0
    19.       Factorial = Factorial * n
    20.       n = n - 1
    21.    Loop
    22. End Function
    23.  
    24. 'returns the permutations of n items taken r at a time; I just like to write mine in the math notation style
    25. Public Function nPr(ByVal n As Long, ByVal r As Long) As Double
    26.    'nPr = n! / (n - r)!
    27.    nPr = 0
    28.    If (n - r) < 0 Then Exit Function
    29.    nPr = Factorial(n) / Factorial(n - r)
    30. End Function
    31.  
    32. 'returns the combinations of n items taken r at a time
    33. Public Function nCr(ByVal n As Long, ByVal r As Long) As Double
    34.    'nCr = n! / (r! * (n - r)!)
    35.    nCr = 0
    36.    If (n - r) < 0 Then Exit Function
    37.    nCr = Factorial(n) / (Factorial(r) * Factorial(n - r))
    38. End Function
    Have fun
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  14. #14
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    What I'm saying, is that once you hit combination number :

    Code:
    NumberOfSquares - IIf(HasEvenNumberOfSquares, 0, 1)
    then you should have enough for a magic square.
    Obviously I mean combinations that fulfill the requirements for a magic square...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  15. #15
    Lively Member
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    89
    Right guys,

    if I can find my old uni project ( Yes, about magic squares ) I'll post a link.

    Ilia

  16. #16
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    I wrote a class in VB.NET to do this, if you want you could port it to vb

    link
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  17. #17
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    Seeing as the other one says it doesn't work with even numbers, I wrote this:

    VB Code:
    1. 'Needs: a command button (Command1), a listbox (List1)
    2.  
    3. Option Explicit
    4.  
    5.  
    6. Private Sub Command1_Click()
    7. Dim i As Long
    8. Dim i2 As Long
    9. Dim i3 As Long
    10. Dim i4 As Long
    11.  
    12. Dim RndVal1 As Long
    13. Dim RndVal2 As Long
    14. Dim RndVal3 As Long
    15.  
    16. Dim Number(1 To 9) As Long
    17. Dim Permutations(1 To 3, 1 To 504) As Long
    18. Dim PermutationsCulled() As Long
    19. Dim TotalNumber As Single
    20.  
    21. 'Here is where you store the numbers. Get them however you feel like,
    22.     'just store them in this array
    23.     'Ex. 0 1 2 4 6 8 5 10 9 should be entered like this:
    24. Number(1) = 0
    25. Number(2) = 1
    26. Number(3) = 2
    27. Number(4) = 4
    28. Number(5) = 6
    29. Number(6) = 8
    30. Number(7) = 5
    31. Number(8) = 10
    32. Number(9) = 9
    33.  
    34. 'Find all 504 permutations
    35. Randomize
    36. For i = 1 To 504
    37. ReInit:
    38.     RndVal1 = Int(Rnd * 9) + 1
    39.     RndVal2 = Int(Rnd * 9) + 1
    40.     RndVal3 = Int(Rnd * 9) + 1
    41.     For i2 = 1 To 504
    42.         If Permutations(1, i2) = RndVal1 And Permutations(2, i2) = RndVal2 And Permutations(3, i2) = RndVal3 Then GoTo ReInit
    43.     Next i2
    44.     Permutations(1, i) = RndVal1
    45.     Permutations(2, i) = RndVal2
    46.     Permutations(3, i) = RndVal3
    47. Next i
    48.  
    49. 'Transfer the array while cutting out all permutations that do not
    50.     'add up to Total Number / 3
    51. ReDim PermutationsCulled(1 To 3, 1 To 1) As Long
    52. For i = 1 To 9
    53.     TotalNumber = TotalNumber + Number(i)
    54. Next i
    55. For i = 1 To 504
    56.     If Number(Permutations(1, i)) + Number(Permutations(2, i)) + Number(Permutations(3, i)) = TotalNumber / 3 Then
    57.         PermutationsCulled(1, UBound(PermutationsCulled, 2)) = Number(Permutations(1, i))
    58.         PermutationsCulled(2, UBound(PermutationsCulled, 2)) = Number(Permutations(2, i))
    59.         PermutationsCulled(3, UBound(PermutationsCulled, 2)) = Number(Permutations(3, i))
    60.        
    61.         If i <> 504 Then ReDim Preserve PermutationsCulled(1 To 3, 1 To UBound(PermutationsCulled, 2) + 1) As Long
    62.     End If
    63. Next i
    64.  
    65. 'Basically, loop through all possible squares and check whether or
    66.     'not it's a magic square. Also, loop through the list and check whether
    67.     'or not it's already been found
    68. For i = 1 To UBound(PermutationsCulled, 2)
    69. For i2 = 1 To UBound(PermutationsCulled, 2)
    70. For i3 = 1 To UBound(PermutationsCulled, 2)
    71.     If PermutationsCulled(1, i) + PermutationsCulled(1, i2) + PermutationsCulled(1, i3) = TotalNumber / 3 Then
    72.     If PermutationsCulled(2, i) + PermutationsCulled(2, i2) + PermutationsCulled(2, i3) = TotalNumber / 3 Then
    73.     If PermutationsCulled(3, i) + PermutationsCulled(3, i2) + PermutationsCulled(3, i3) = TotalNumber / 3 Then
    74.         For i4 = 0 To List1.ListCount - 1 Step 4
    75.             If List1.List(i4) = PermutationsCulled(1, i) & " " & PermutationsCulled(2, i) & " " & PermutationsCulled(3, i) Then
    76.             If List1.List(i4 + 1) = PermutationsCulled(1, i2) & " " & PermutationsCulled(2, i2) & " " & PermutationsCulled(3, i2) Then
    77.             If List1.List(i4 + 2) = PermutationsCulled(1, i3) & " " & PermutationsCulled(2, i3) & " " & PermutationsCulled(3, i3) Then
    78.                 GoTo SkipIf
    79.             End If
    80.             End If
    81.             End If
    82.         Next i4
    83.        
    84.         List1.AddItem PermutationsCulled(1, i) & " " & PermutationsCulled(2, i) & " " & PermutationsCulled(3, i)
    85.         List1.AddItem PermutationsCulled(1, i2) & " " & PermutationsCulled(2, i2) & " " & PermutationsCulled(3, i2)
    86.         List1.AddItem PermutationsCulled(1, i3) & " " & PermutationsCulled(2, i3) & " " & PermutationsCulled(3, i3)
    87.         List1.AddItem ""
    88.        
    89.         Me.Refresh
    90.         DoEvents
    91.     End If
    92.     End If
    93.     End If
    94. SkipIf:
    95. Next i3
    96. Next i2
    97. Next i
    98. End Sub

    It really is remarkable fast for the number of loops involved. Good luck
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  18. #18
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    Well, I edited it seeing as it was using numbers more than once in the same box:

    VB Code:
    1. 'Needs: a command button (Command1), a listbox (List1)
    2.  
    3. Option Explicit
    4.  
    5.  
    6. Private Sub Command1_Click()
    7. Dim i As Long
    8. Dim i2 As Long
    9. Dim i3 As Long
    10. Dim i4 As Long
    11. Dim i5 As Long
    12.  
    13. Dim RndVal1 As Long
    14. Dim RndVal2 As Long
    15. Dim RndVal3 As Long
    16.  
    17. Dim Number(1 To 9) As Long
    18. Dim Permutations(1 To 3, 1 To 504) As Long
    19. Dim PermutationsCulled() As Long
    20. Dim CrossCheck(1 To 9) As Long
    21. Dim TotalNumber As Single
    22.  
    23. 'Here is where you store the numbers. Get them however you feel like,
    24.     'just store them in this array
    25.     'Ex. 0 1 2 4 6 8 5 10 9 should be entered like this:
    26. Number(1) = 0
    27. Number(2) = 1
    28. Number(3) = 2
    29. Number(4) = 4
    30. Number(5) = 6
    31. Number(6) = 8
    32. Number(7) = 5
    33. Number(8) = 10
    34. Number(9) = 9
    35.  
    36. 'Find all 504 permutations
    37. Randomize
    38. For i = 1 To 504
    39. ReInit:
    40.     RndVal1 = Int(Rnd * 9) + 1
    41.     RndVal2 = Int(Rnd * 9) + 1
    42.     RndVal3 = Int(Rnd * 9) + 1
    43.     Do Until RndVal2 <> RndVal1
    44.         RndVal2 = Int(Rnd * 9) + 1
    45.     Loop
    46.     Do Until RndVal3 <> RndVal2 And RndVal3 <> RndVal1
    47.         RndVal3 = Int(Rnd * 9) + 1
    48.     Loop
    49.     For i2 = 1 To 504
    50.         If Permutations(1, i2) = RndVal1 And Permutations(2, i2) = RndVal2 And Permutations(3, i2) = RndVal3 Then GoTo ReInit
    51.     Next i2
    52.     Permutations(1, i) = RndVal1
    53.     Permutations(2, i) = RndVal2
    54.     Permutations(3, i) = RndVal3
    55. Next i
    56.  
    57. 'Transfer the array while cutting out all permutations that do not
    58.     'add up to Total Number / 3 plus checking to make sure all numbers
    59.     'in Number array are used exactly once and displaying the % done
    60. ReDim PermutationsCulled(1 To 3, 1 To 1) As Long
    61. For i = 1 To 9
    62.     TotalNumber = TotalNumber + Number(i)
    63. Next i
    64. For i = 1 To 504
    65.     If Number(Permutations(1, i)) + Number(Permutations(2, i)) + Number(Permutations(3, i)) = TotalNumber / 3 Then
    66.         PermutationsCulled(1, UBound(PermutationsCulled, 2)) = Number(Permutations(1, i))
    67.         PermutationsCulled(2, UBound(PermutationsCulled, 2)) = Number(Permutations(2, i))
    68.         PermutationsCulled(3, UBound(PermutationsCulled, 2)) = Number(Permutations(3, i))
    69.        
    70.         If i <> 504 Then ReDim Preserve PermutationsCulled(1 To 3, 1 To UBound(PermutationsCulled, 2) + 1) As Long
    71.     End If
    72. Next i
    73.  
    74. 'Basically, loop through all possible squares and check whether or
    75.     'not it's a magic square. Also, loop through the list and check whether
    76.     'or not it's already been found
    77. For i = 1 To UBound(PermutationsCulled, 2)
    78. For i2 = 1 To UBound(PermutationsCulled, 2)
    79. For i3 = 1 To UBound(PermutationsCulled, 2)
    80.     If PermutationsCulled(1, i) + PermutationsCulled(1, i2) + PermutationsCulled(1, i3) = TotalNumber / 3 Then
    81.     If PermutationsCulled(2, i) + PermutationsCulled(2, i2) + PermutationsCulled(2, i3) = TotalNumber / 3 Then
    82.     If PermutationsCulled(3, i) + PermutationsCulled(3, i2) + PermutationsCulled(3, i3) = TotalNumber / 3 Then
    83.         For i4 = 0 To List1.ListCount - 1 Step 4
    84.             If List1.List(i4) = PermutationsCulled(1, i) & " " & PermutationsCulled(2, i) & " " & PermutationsCulled(3, i) Then
    85.             If List1.List(i4 + 1) = PermutationsCulled(1, i2) & " " & PermutationsCulled(2, i2) & " " & PermutationsCulled(3, i2) Then
    86.             If List1.List(i4 + 2) = PermutationsCulled(1, i3) & " " & PermutationsCulled(2, i3) & " " & PermutationsCulled(3, i3) Then
    87.                 GoTo SkipIf
    88.             End If
    89.             End If
    90.             End If
    91.         Next i4
    92.        
    93.         For i4 = 1 To 9
    94.             CrossCheck(i4) = Number(i4)
    95.         Next i4
    96.         For i4 = 1 To 3
    97.             For i5 = 1 To 9
    98.                 If CrossCheck(i5) = PermutationsCulled(i4, i) And CrossCheck(i5) <> 0 Then
    99.                     CrossCheck(i5) = 0
    100.                     Exit For
    101.                 End If
    102.             Next i5
    103.         Next i4
    104.         For i4 = 1 To 3
    105.             For i5 = 1 To 9
    106.                 If CrossCheck(i5) = PermutationsCulled(i4, i2) And CrossCheck(i5) <> 0 Then
    107.                     CrossCheck(i5) = 0
    108.                     Exit For
    109.                 End If
    110.             Next i5
    111.         Next i4
    112.         For i4 = 1 To 3
    113.             For i5 = 1 To 9
    114.                 If CrossCheck(i5) = PermutationsCulled(i4, i3) And CrossCheck(i5) <> 0 Then
    115.                     CrossCheck(i5) = 0
    116.                     Exit For
    117.                 End If
    118.             Next i5
    119.         Next i4
    120.         i5 = 0
    121.         For i4 = 1 To 9
    122.             i5 = i5 + CrossCheck(i4)
    123.         Next i4
    124.        
    125.         If i5 <> 0 Then GoTo SkipIf
    126.        
    127.         List1.AddItem PermutationsCulled(1, i) & " " & PermutationsCulled(2, i) & " " & PermutationsCulled(3, i)
    128.         List1.AddItem PermutationsCulled(1, i2) & " " & PermutationsCulled(2, i2) & " " & PermutationsCulled(3, i2)
    129.         List1.AddItem PermutationsCulled(1, i3) & " " & PermutationsCulled(2, i3) & " " & PermutationsCulled(3, i3)
    130.         List1.AddItem ""
    131.        
    132.         Me.Refresh
    133.         DoEvents
    134.     End If
    135.     End If
    136.     End If
    137. SkipIf:
    138. Next i3
    139. Next i2
    140. Command1.Caption = Int(i / UBound(PermutationsCulled, 2) * 100) & "%"
    141. Next i
    142.  
    143. Command1.Caption = "Command1"
    144. End Sub

    That should give you every single magic square a block of numbers can make. Again, it's amazingly fast for all the loops it uses. Please do note that the more possible magic square there are, the longer it will take (ie, [2, 2, 2, 2, 2, 2, 2, 2, 2] will take forever compared to [0, 1, 2, 4, 6, 8, 5, 10, 9] which will take maybe half a second]

    Edit: Somehow my mind wandered back to this and thought the diagonals aren't being checked (though they aren't mentioned in the problem). To check them too, you'd use this:

    VB Code:
    1. If PermutationsCulled(1, i) + PermutationsCulled(1, i2) + PermutationsCulled(1, i3) = TotalNumber / 3 Then
    2.     If PermutationsCulled(2, i) + PermutationsCulled(2, i2) + PermutationsCulled(2, i3) = TotalNumber / 3 Then
    3.     If PermutationsCulled(3, i) + PermutationsCulled(3, i2) + PermutationsCulled(3, i3) = TotalNumber / 3 Then
    4.     [b]If PermutationsCulled(1, i) + PermutationsCulled(2, i2) + PermutationsCulled(3, i3) = TotalNumber / 3 Then[/b]
    5.     [b]If PermutationsCulled(3, i) + PermutationsCulled(2, i2) + PermutationsCulled(1, i3) = TotalNumber / 3 Then[/b]

    with the proper End If's
    Last edited by jemidiah; Oct 13th, 2003 at 06:06 PM.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width