then I can ask you to share your listing again, there must be something wrong not mine, because I don’t get to those lines.

Thanks so much for your help

then I can ask you to share your listing again, there must be something wrong not mine, because I don’t get to those lines.

Thanks so much for your help

This is the code I used to output the list:

```
Dim x() as integer=array(40,44,48,56,64,66,72,100)
'Numerator loops
for a as Integer = 0 to x.Ubound-2
for c as Integer = a+1 to x.Ubound-1
for e as Integer = c+1 to x.Ubound
'denominator loops
for b as Integer = 0 to x.Ubound-2
for d as Integer = b+1 to x.Ubound-1
for f as Integer = d+1 to x.Ubound
'Output this combination to text field
tf1.AppendText "("+str(x(a))+" x "+str(x(c))+" x "+str(x(e))+") / ("+str(x(b))+" x "+str(x(d))+" x "+str(x(f))+")"+EndOfLine
next
next
next
next
next
next
```

```
''OUTPUT FORMULA: R= (A*C*E)/(B*D*F)
dim start as integer
start = System.Microseconds
var output as string
Var file As FolderItem = SpecialFolder.Desktop.Child("testOutPut.csv")
Var t As TextOutputStream = TextOutputStream.Create(file)
Dim x() as integer=array(40,44,48,56,64,66,72,100)
'Numerator loops
for a as Integer = 0 to x.Ubound-2
for c as Integer = a+1 to x.Ubound-1
for e as Integer = c+1 to x.Ubound
'denominator loops
for b as Integer = 0 to x.Ubound-2
for d as Integer = b+1 to x.Ubound-1
for f as Integer = d+1 to x.Ubound
'Output this combination to text field
t.WriteLine "("+str(x(a))+" x "+str(x(c))+" x "+str(x(e))+") / ("+str(x(b))+" x "+str(x(d))+" x "+str(x(f))+")"+EndOfLine
next
next
next
next
next
next
t.close
MessageBox str((System.Microseconds - start) / 1000000) + " seconds"
```

I had to replace just a few things related to the file, maybe it changes according to the version of Xojo.

But the result still doesn’t work… there are equal values in the list of results, for example, in the 1st line the numbers 40 - 44 - 48 are repeated, in the 3rd line 40 -44 is repeated, in the 5th line 40-44

…

…

…

49 line are repeated on 44-48

Those lines in the numerator are repeating, because the lines in the denominator are changing, but the value of the fraction is different for each line.I thought that is what you asked for.

I had earlier set up the loops so that numbers in the numerator could not appear in the denominator, but you said that was wrong.

Excuse me I need to have all possible combinations, without repetition, unless the same number is inserted into the array several times. I’m testing the various codes from time to time, but if I wrote that it was wrong it was because in the output table, there was something wrong.

Among all the codes you sent me, this is the one that comes closest … but if you notice well in the table, some values are missing in the numerator such as 72 and 100

```
''OUTPUT FORMULA: R= (A*C*E)/(B*D*F)
dim start as integer
start = System.Microseconds
var output as string
Dim ArrayIngranaggi() as integer=array(40,44,48,56,64,66,72,100)
Dim ArraiIngranaggiRuotaA() as integer=ArrayIngranaggi()
Dim ArraiIngranaggiRuotaB() as integer=ArrayIngranaggi()
Dim ArraiIngranaggiRuotaC() as integer=ArrayIngranaggi()
Dim ArraiIngranaggiRuotaD() as integer=ArrayIngranaggi()
Dim ArraiIngranaggiRuotaE() as integer=ArrayIngranaggi()
Dim ArraiIngranaggiRuotaF() as integer=ArrayIngranaggi()
Dim VisualizzaStringa as string
Var file As FolderItem = SpecialFolder.Desktop.Child("testOutPut.csv")
Var t As TextOutputStream = TextOutputStream.Create(file)
Dim R as currency
Dim ace,bdf as integer
Dim A,B,C,D,E,F as integer
For A=0 To ArraiIngranaggiRuotaA.LastIndex-5
For C=A+1 To ArraiIngranaggiRuotaB.LastIndex-4
For E=C+1 To ArraiIngranaggiRuotaC.LastIndex-3
For B=E+1 To ArraiIngranaggiRuotaD.LastIndex-2
For D=B+1 To ArraiIngranaggiRuotaE.LastIndex-1
For F=D+1 To ArraiIngranaggiRuotaF.LastIndex
ace = ArraiIngranaggiRuotaA(a) * ArraiIngranaggiRuotaC(c) * ArraiIngranaggiRuotaE(e)
bdf = ArraiIngranaggiRuotaB(b) * ArraiIngranaggiRuotaD(d) * ArraiIngranaggiRuotaF(f)
R = ace / bdf
VisualizzaStringa="("+ArraiIngranaggiRuotaA(A).ToText+"x" +ArraiIngranaggiRuotaC(C).ToText+"x"+ArraiIngranaggiRuotaE(E).ToText + " / " +ArraiIngranaggiRuotaB(B).ToText+"x"+ArraiIngranaggiRuotaD(D).ToText+"x"+ArraiIngranaggiRuotaF(F).ToText+")"
output = str(ArraiIngranaggiRuotaA(A)) + "**" + str(ArraiIngranaggiRuotaB(B)) + "**" + str(ArraiIngranaggiRuotaC(C)) + "**" + str(ArraiIngranaggiRuotaD(D)) + "**" + str(ArraiIngranaggiRuotaE(E)) + "**" + str(ArraiIngranaggiRuotaF(F)) + "**" +"-------"+ "**" + VisualizzaStringa + "**" +" ------------"+"**"+ str(R)
t.writeline(output)
Next
Next
Next
Next
Next
Next
t.close
MessageBox str((System.Microseconds - start) / 1000000) + " seconds"
```

It might be easier if we could look at a smaller version of the of the problem. For example, let’s consider a simpler fraction: (A * C) / (B * D), and an array with only 5 elements: (40,44,48,56,64). Then the different loop parameters would produce a much smaller output list which would be easier analyze.

Look, in a very improvised way, I tried to add lines to reverse denominator with numerator, and I got a much more complete list of combinations…

```
''OUTPUT FORMULA: R= (A*C*E)/(B*D*F)
dim start as integer
start = System.Microseconds
var output as string
Dim ArrayIngranaggi() as integer=array(40,44,48,56,64,66,72,100)
Dim ArraiIngranaggiRuotaA() as integer=ArrayIngranaggi()
Dim ArraiIngranaggiRuotaB() as integer=ArrayIngranaggi()
Dim ArraiIngranaggiRuotaC() as integer=ArrayIngranaggi()
Dim ArraiIngranaggiRuotaD() as integer=ArrayIngranaggi()
Dim ArraiIngranaggiRuotaE() as integer=ArrayIngranaggi()
Dim ArraiIngranaggiRuotaF() as integer=ArrayIngranaggi()
Dim VisualizzaStringa as string
Var file As FolderItem = SpecialFolder.Desktop.Child("testOutPut.csv")
Var t As TextOutputStream = TextOutputStream.Create(file)
Dim R as currency
Dim ace,bdf as integer
Dim A,B,C,D,E,F as integer
For A=0 To ArraiIngranaggiRuotaA.LastIndex-5
For C=A+1 To ArraiIngranaggiRuotaB.LastIndex-4
For E=C+1 To ArraiIngranaggiRuotaC.LastIndex-3
For B=E+1 To ArraiIngranaggiRuotaD.LastIndex-2
For D=B+1 To ArraiIngranaggiRuotaE.LastIndex-1
For F=D+1 To ArraiIngranaggiRuotaF.LastIndex
ace = ArraiIngranaggiRuotaA(a) * ArraiIngranaggiRuotaC(c) * ArraiIngranaggiRuotaE(e)
bdf = ArraiIngranaggiRuotaB(b) * ArraiIngranaggiRuotaD(d) * ArraiIngranaggiRuotaF(f)
R = ace / bdf
VisualizzaStringa="("+ArraiIngranaggiRuotaA(A).ToText+"x" +ArraiIngranaggiRuotaC(C).ToText+"x"+ArraiIngranaggiRuotaE(E).ToText + " / " +ArraiIngranaggiRuotaB(B).ToText+"x"+ArraiIngranaggiRuotaD(D).ToText+"x"+ArraiIngranaggiRuotaF(F).ToText+")"
output = str(ArraiIngranaggiRuotaA(A)) + "**" + str(ArraiIngranaggiRuotaB(B)) + "**" + str(ArraiIngranaggiRuotaC(C)) + "**" + str(ArraiIngranaggiRuotaD(D)) + "**" + str(ArraiIngranaggiRuotaE(E)) + "**" + str(ArraiIngranaggiRuotaF(F)) + "**" +"-------"+ "**" + VisualizzaStringa + "**" +" ------------"+"**"+ str(R)
t.writeline(output)
Next
Next
Next
Next
Next
Next
For F=0 To ArraiIngranaggiRuotaF.LastIndex-5
For E=F+1 To ArraiIngranaggiRuotaE.LastIndex-4
For D=E+1 To ArraiIngranaggiRuotaD.LastIndex-3
For C=D+1 To ArraiIngranaggiRuotaC.LastIndex-2
For B=C+1 To ArraiIngranaggiRuotaB.LastIndex-1
For A=B+1 To ArraiIngranaggiRuotaA.LastIndex
ace = ArraiIngranaggiRuotaA(a) * ArraiIngranaggiRuotaC(c) * ArraiIngranaggiRuotaE(e)
bdf = ArraiIngranaggiRuotaB(b) * ArraiIngranaggiRuotaD(d) * ArraiIngranaggiRuotaF(f)
R = ace / bdf
VisualizzaStringa="("+ArraiIngranaggiRuotaA(A).ToText+"x" +ArraiIngranaggiRuotaC(C).ToText+"x"+ArraiIngranaggiRuotaE(E).ToText + " / " +ArraiIngranaggiRuotaB(B).ToText+"x"+ArraiIngranaggiRuotaD(D).ToText+"x"+ArraiIngranaggiRuotaF(F).ToText+")"
output = str(ArraiIngranaggiRuotaA(A)) + "**" + str(ArraiIngranaggiRuotaB(B)) + "**" + str(ArraiIngranaggiRuotaC(C)) + "**" + str(ArraiIngranaggiRuotaD(D)) + "**" + str(ArraiIngranaggiRuotaE(E)) + "**" + str(ArraiIngranaggiRuotaF(F)) + "**" +"-------"+ "**" + VisualizzaStringa + "**" +" ------------"+"**"+ str(R)
t.writeline(output)
Next
Next
Next
Next
Next
Next
t.close
MessageBox str((System.Microseconds - start) / 1000000) + " seconds"
```

Now I’m not sure if that’s all the combinations I can get, but there’s definitely a lot more than before…not an easy problem to fix.

Okay, I think I finally understand what you’re trying to do. This is neither a permutation nor combination situation, but a combination of both. I doubt that there is any way to do this with just loop parameters. It will also require some conditional tests. Here is some new code that you can test:

```
Dim x() as integer=array(40,44,48,56,64,66,72,100)
efOut.AppendText "a c e b d f"+EndOfLine
'Numerator loops
for a as Integer = 0 to x.Ubound-2
for c as Integer = a+1 to x.Ubound-1
for e as Integer = c+1 to x.Ubound
'denominator loops
for b as Integer = 0 to x.Ubound-2
if b=a or b=c or b=e then Continue
for d as Integer = b+1 to x.Ubound-1
if d=a or d=c or d=e then Continue
for f as Integer = d+1 to x.Ubound
if f=a or f=c or f=e then Continue
'Append this combination to output
efOut.AppendText "("+str(x(a))+" x "+str(x(c))+" x "+str(x(e))+") / ("+str(x(b))+" x "+str(x(d))+" x "+str(x(f))+")"+EndOfLine
next
next
next
next
next
next
```

Here is a link to the output file produced by this code.

http://electronbunker.ca/XojoProjects/acebdf_List.txt

Im still mildly curious about why this is wanted. (The real-world scenario)

Yes Robert, now it’s much much better, I have many combinations of numbers … it’s really a problem to understand if they are all there, but it’s an excellent basis for having results. Thank you very much for your advice. Your code is very accurate, compact and fast. I’m really happy.

I’m building a mechanical tool for making gears. I already own some gears and I wanted to understand with the ones I have, how many combinations I can make (2 gears, 4 gears with two in pairs, and 6 gears with 2 pairs) … with the 6 gears I get the maximum ratios I can have with my gears. This ratio combined with that of my mechanical divider, will allow me to carve the teeth. Now I have to try the results to understand if everything works.

Hello federico, I remember posting, some time ago, a couple of algorithms for computing permutations without repetition. See if they might be useful, you can find them in the forum at this link Looking for unique number of Base X - #5 by Andrew_Lambert

Heap’s algorithm generates n permutations from a set of n numbers. It’s not applicable in this situation.

Forum for Xojo Programming Language and IDE. Copyright © 2024 Xojo, Inc.