Magic esquire 3x3

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,

Is it possible to create all possible magic esquire 3x3 which total must be 14 using 0 to 8 numbers? Numbers can be used repeated

Like example shown below...


Book1
ABCDEF
1
2
30312
41021
52032
63
74521
85203
96010
107
118321
12114
13101
14
15320
16122
17013
18
19310
20151
21120
22
23521
24003
25012
26
27221
28322
29110
30
31322
32211
33012
34
35421
36001
37231
38
39160
40222
41100
42
43013
44113
45122
46
47122
48111
49123
50
51212
52112
53131
54
55621
56301
57001
58
59
Sheet2


Thank you all
Excel 2000
Regards,
Moti
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Is it possible to generate all 308,187 permutations with my excel version 2000?
 
Upvote 0
with a macro you can print the first 50000 in col A - the next 5000 in col B etc - would that suit ?
 
Upvote 0
it is a lot of work to code - I cannot spare the time at present - try yourself - cycle A,B,C,D,E,F,G,H FROM 0 to 8 and if the total = 14 stores the values of A to H in an array - then print first 50000 values in col A - next 50000 in col B

to do this use

for j=1 to 7
for k = 1 to 50000
sum=sum+1
cells(j,k)= a(sum)&b(sum)&.......etc
next k
next j
 
Upvote 0
Code:
Sub moti()
  Const m           As Long = 9
  Const iTgt As Long = 14
  Dim i             As Long
  Dim n             As Long
  Dim aiInx(1 To 9) As Long
  Dim aiMin(1 To 9) As Long
  Dim aiMax(1 To 9) As Long
  Dim aiOut(1 To 64000, 1 To 9) As Long
  Dim iSum          As Long

  For i = 1 To m
    aiMax(i) = 8
  Next i

  NestedFor aiInx, aiMin, aiMax, True

  Do While NestedFor(aiInx, aiMin, aiMax)
    iSum = 0
    For i = 1 To m
      iSum = iSum + aiInx(i)
      If iSum > iTgt Then Exit For
    Next i

    If iSum = iTgt Then
      n = n + 1

      For i = 1 To m
        aiOut(n, i) = aiInx(i)
      Next i

      If n >= 64000 Then
        Cells(1, Columns.Count).End(xlToLeft).Offset(, 2).Resize(n, 9).Value = aiOut
        Erase aiOut
        n = 0
      End If
      
      If (n And &H3FF&) = 0& Then
        Application.StatusBar = Format(n, "#,##0")
        DoEvents
      End If
    End If
  Loop

  If n Then Cells(1, Columns.Count).End(xlToLeft).Offset(, 2).Resize(n, 9).Value = aiOut
  
  Application.StatusBar = False
End Sub
The function remains is unchanged.
 
Upvote 0
Code:
Sub moti()
End Sub
The function remains is unchanged.
shg,Thank you so much for modifying the code to work with my version, I am away from my desk computer 3 days because I am out of city, will check on 17th and give you conformation


Have a nice day

Regards,
Moti
 
Upvote 0
shg,Thank you so much for modifying the code to work with my version, I am away from my desk computer 3 days because I am out of city, will check on 17th and give you conformation


Have a nice day

Regards,
Moti
Wow shg, code works like magic with my version, it took time 00:01:01 second to generate all 308,187 sets through C to AY columns

Many thanks for your kind help

Have a nice day

Good Luck

Kind Regards,
Moti :)
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top