# Compare a succession of numbers

## Recommended Posts

I would like to carry out all possible calculations with the operators X, +, - and/of a succession of 10 numbers to approach my result as much as possible. I cannot too how make???

I have my result => \$result = 24

and the sucession of 10 numbers =>

\$number[0] = 12

\$number[1] = 4

\$number[2] = 37

...

...

...

...

...

...

\$number[9] = 20

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

Yes, it is that but except that in fact each number can be used only once, and the 10 numbers must be used.

Thank you

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

ok ! !

```\$result = 24
\$temp = ""
Dim \$number[10] = [12, 4, 37, 45, 35, 67, 43, 22, 38, 20]
Dim \$op[4] = ["+", "-", "*", "/"]

\$nearby = 999999
\$currentnext = 999999
\$bestchoice = ""
\$allchoices = ""
For \$i = 0 To 9
For \$j = 0 To 9
For \$k = 0 To 3
Assign("temp", "\$number[\$i]" & \$op[\$k] & "\$number[\$j]")
\$T1 = Execute(\$temp)
;ConsoleWrite(\$T1 & @CRLF)
\$nearby = Abs(\$T1 - \$result)
If \$currentnext > \$nearby Then
\$currentnext = \$nearby
\$bestchoice = \$number[\$i] & \$op[\$k] & \$number[\$j]
If \$currentnext = 0 Then ExitLoop
EndIf
Next
Next
Next
MsgBox(0, "first best choice is", \$bestchoice)```

In this example \$bestchoice = 12 + 12. We can see the number 12 is used twice...

This code is good, but in fact we can't use a number several times. And each number must be use to approach to the maximum of the result.

Edited by jerem488

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

I'm very sorry...

But i would to find the result by using ALL THE NUMBERS

I will give an example for better understanding :

For example I have this numbers :

\$number[10] = [12, 4, 37, 45, 35, 67, 43, 22, 38, 20]

the result is 49

the solution is ==>> 12+22+38/20*4+35-67+37+45-43 (its an example of course) The result is perhaps not good but it's for the principle

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

This is with an aim of creating a play (for the school). I already carried out the play or we must guess a number which is between 2 other numbers.

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

Nobody want to help me ??

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

```#include <Array.au3>

Global \$array[1]
Global \$number[11] = ["",12, 4, 37, 45, 35, 67, 43, 22, 38, 20]

\$Operator = StringSplit("+,-,*,/",",")

\$sHold = ""
\$solutions = ""

_All_Combinations("")
Func _All_Combinations(\$sString)
Dim \$i
If StringLen(\$sString) = 9 Then
\$sHold &= \$sString & "|"
Return
EndIf
For \$i = 1 to 4
_All_Combinations(\$sString & \$Operator[\$i])
Next
EndFunc
\$array = StringSplit(StringTrimRight(\$sHold,1),"|")

For \$i = 1 to (UBound(\$array) - 1)
\$equation = ""
For \$j = 1 to 9
Next
\$equation &= \$number[10]
\$solutions &= Execute(\$equation) & "|"
Next
\$solutions = StringSplit(StringTrimRight(\$solutions,1),"|")

_ArrayDisplay(\$solutions)```

Let it run....it takes a while!!

Edited by andybiochem

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

##### Share on other sites

```Global \$array[1]
Global \$number[11] = ["",12, 4, 37, 45, 35, 67, 43, 22, 38, 20]

\$Operator = StringSplit("+,-,*,/",",")

\$sHold = ""
\$solutions = ""
\$SolutionToFind = 24

_All_Combinations("")
Func _All_Combinations(\$sString)
Dim \$i
If StringLen(\$sString) = 9 Then
\$sHold &= \$sString & "|"
Return
EndIf
For \$i = 1 to 4
_All_Combinations(\$sString & \$Operator[\$i])
Next
EndFunc
\$array = StringSplit(StringTrimRight(\$sHold,1),"|")

For \$i = 1 to (UBound(\$array) - 1)
\$equation = ""
For \$j = 1 to 9
Next
\$equation &= \$number[10]
If Execute(\$equation) = \$SolutionToFind Then \$solutions &= Execute(\$equation) & " = " & \$equation & @CRLF
Next

MsgBox(0,"",\$solutions)```

Gives:

24 = 12+4*37+45-35-67-43+22-38-20

24 = 12+4*37-45-35+67-43-22-38-20

24 = 12-4*37+45-35+67+43+22+38-20

24 = 12/4+37-45-35+67-43+22+38-20

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

##### Share on other sites

```Global \$array[1]
Global \$number[11] = ["",12, 4, 37, 45, 35, 67, 43, 22, 38, 20]

\$Operator = StringSplit("+,-,*,/",",")

\$sHold = ""
\$solutions = ""
\$SolutionToFind = 24

_All_Combinations("")
Func _All_Combinations(\$sString)
Dim \$i
If StringLen(\$sString) = 9 Then
\$sHold &= \$sString & "|"
Return
EndIf
For \$i = 1 to 4
_All_Combinations(\$sString & \$Operator[\$i])
Next
EndFunc
\$array = StringSplit(StringTrimRight(\$sHold,1),"|")

For \$i = 1 to (UBound(\$array) - 1)
\$equation = ""
For \$j = 1 to 9
Next
\$equation &= \$number[10]
If Execute(\$equation) = \$SolutionToFind Then \$solutions &= Execute(\$equation) & " = " & \$equation & @CRLF
Next

MsgBox(0,"",\$solutions)```

Gives:

24 = 12+4*37+45-35-67-43+22-38-20

24 = 12+4*37-45-35+67-43-22-38-20

24 = 12-4*37+45-35+67+43+22+38-20

24 = 12/4+37-45-35+67-43+22+38-20

Very thanks

I went test it

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

I have seen in the suite of numbers, it make operations in order of numbers are done.

How do we do to do all operations possible (to put the first number in the second place, etc... for all numbers)

thanks

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

Hello everybody

Let me run this code for each line of a text file.

In each row, the first 8 numbers are the numbers for the calculation and the last of the line is the result to find.

And I want him running this code to each line of text file.

And then he copied the solutions in another text file.

It's been almost 3 weeks that I had trouble finding a solution that works, but I can not find anything.

Thanks

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

Hello everybody

Let me run this code for each line of a text file.

In each row, the first 8 numbers are the numbers for the calculation and the last of the line is the result to find.

And I want him running this code to each line of text file.

And then he copied the solutions in another text file.

It's been almost 3 weeks that I had trouble finding a solution that works, but I can not find anything.

Thanks

I believe andybiochem has posted a solution that works in Post # 8, this thread.

The solution is in the variable named \$solutions.

I added the _DebugOut () function which outputs to NotePad. With this you can see the 292,144 equations used to find the solution(s). If you save these equations in NotePad to a text file, the file is just over 16Mb in size.

```#include <Debug.au3>
Global \$array[1], \$iNo = 0
Global \$number[11] = ["",12, 4, 37, 45, 35, 67, 43, 22, 38, 20]
_DebugSetup ("Results")

\$Operator = StringSplit("+,-,*,/",",")

\$sHold = ""
\$solutions = ""
\$SolutionToFind = 24

_All_Combinations("")

\$array = StringSplit(StringTrimRight(\$sHold,1),"|")

For \$i = 1 to (UBound(\$array) - 1)
\$equation = ""
For \$j = 1 to 9
Next
\$equation &= \$number[10]
If Execute(\$equation) = \$SolutionToFind Then \$solutions &= \$equation & " = " & Execute(\$equation) & @CRLF
\$iNo += 1
_DebugOut ("Equat.No. " & \$iNo & "  is   " & \$equation & "  =  " & Execute(\$equation) )
Next
_DebugOut ( @CRLF & \$solutions)

MsgBox(0,"",\$solutions)

Func _All_Combinations(\$sString)
Dim \$i
If StringLen(\$sString) = 9 Then
\$sHold &= \$sString & "|"
Return
EndIf
For \$i = 1 to 4
_All_Combinations(\$sString & \$Operator[\$i])
Next
EndFunc```

If you play around with the string in the _DebugOut () function, you should be able to change the output to NotePad the way you prefer.

##### Share on other sites

Sorry,...

maybe I expressed myself poorly, but in fact I want to change this line:

`Global \$number[11] = ["",12, 4, 37, 45, 35, 67, 43, 22, 38, 20]`

from a list that I have in a text file.

My text file is similar to this :

12, 4, 37, 45, 35, 67, 43, 22, 38, 20

49, 36, 12, 2, 13, 45, 81, 46, 90, 28

etc...

And in each row, the last number is the result that it must find.

And the other numbers are those that must be used for operation

And then save the results of the function in another text file.

Thank you

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

Sorry,...

maybe I expressed myself poorly, but in fact I want to change this line:

```Global \$number[11] = ["",12, 4, 37, 45, 35, 67, 43, 22, 38, 20]oÝ÷ Ùúè©b²ÛajÒ!j÷¢«^Æ×âã2µìm~)^Ë")Z®Ú-+5Ûûãùë¾7ÛmüÛN=ß­vÛ]øçÍxëÝ6ñëwbæº0¶¥jËgºfÞ®+-êÞ²ém¶­Ù®²×âÐ'vØ^¢Ø^®{¦mêìj·­¶­ë-më¬y×è®^­«b¢p'vØ^Æ¯zØ^­ë.Û(~Ø^~éÜ¶*'v§¢Ø^®×±µø¥y8ZL¨»ú®¢×ºÇ¶¬jËaz)éº×âã2Më-)^·¡×£vã~øç~zïöÛ6Ówë]¶×~9ó^:÷M¼×n7ómµëm6ã]¸ßÍ¶ÛM¸ýÊyº1
²)í Ú-zÂ+a¶­Ù^3\$Þ²Ñbä^²ém±8b±Æ§më½çZ±«^Æ×âæ®¶­sb6æ6ÇVFRfÇC´FV'VræS2fwC° £²GG¢ò÷wwræWFöG67&Bæ6öÒöf÷'VÒöæFWç÷3Òf×·6÷wF÷3Ó#Cf×·fWsÖfæG÷7Bf×·ÓSsP¤vÆö&Âb33c·4öÆBÂb33c·6öÇWFöç2Âb33c´÷W&F÷"Âb33c¶çVÖ&W ¤Æö6Âb33c·&W0 ¢b33c¶fÆRÒfÆT÷VâgV÷C´×FW7DfÆRçGBgV÷C²Â´gVÆÂFæBfÆRæÖRöbçWBfÆRÖ&RæVVFVBW&P¤bb33c¶fÆRÒÓFVà ×6t&÷ÂgV÷C´W'&÷"gV÷C²ÂgV÷CµVæ&ÆRFò÷VâfÆRâgV÷C² W@¤VæD` ¥ôFV'Vu6WGWgV÷C´×FW7DfÆU&W7VÇG2gV÷C²²æÖRöb÷WGWBfÆR ¥vÆR b33c¶ÆæRÒfÆU&VDÆæRb33c¶fÆR bW'&÷"ÒÓFVâWDÆö÷ b33c¶ÆæRÒ7G&æu7ÆBb33c¶ÆæRÂgV÷C²ÂgV÷C² Æö6Âb33c¶fÆTÆæU²b33c¶ÆæU³ÕÐ f÷"b33c·rÒFòT&÷VæBb33c¶fÆTÆæRÒ b33c¶fÆTÆæU²b33c·uÒÒb33c¶ÆæU²b33c·r²Ð æW@ 6öÖ&æFöäç2b33c¶fÆTÆæR¥tVæ@¥ôFV'Vt÷WB5\$Äbf×²gV÷C²TäBgV÷C²¤fÆT6Æ÷6Rb33c¶fÆR  ¤gVæ26öÖ&æFöäç2b33c¶fÆTÆæT'& vÆö&Âb33c¶'&³ÒÂb33c¶æòÒ vÆö&Âb33c¶çVÖ&W%µT&÷VæBb33c¶fÆTÆæT'&Ð b33c¶çVÖ&W%³ÒÒgV÷C²gV÷C° f÷"b33c·"ÒFòT&÷VæBb33c¶çVÖ&W"Ò b33c¶çVÖ&W%²b33c·%ÒÒb33c¶fÆTÆæT'&²b33c·"ÒÐ æW@ b33c´÷W&F÷"Ò7G&æu7ÆBgV÷C²²ÂÒÂ¢ÂògV÷C²ÂgV÷C²ÂgV÷C² b33c·4öÆBÒgV÷C²gV÷C° b33c·6öÇWFöç2ÒgV÷C²gV÷C° b33cµ6öÇWFöåFôfæBÒb33c¶fÆTÆæT'&µT&÷VæBb33c¶fÆTÆæT'&ÒÐ ôÆÅô6öÖ&æFöç2gV÷C²gV÷C² b33c¶'&Ò7G&æu7ÆB7G&æuG&Õ&vBb33c·4öÆBÂÂgV÷C·ÂgV÷C² f÷"b33c¶ÒFòT&÷VæBb33c¶'&Ò b33c¶WVFöâÒgV÷C²gV÷C° b33c¶FFÒ7G&æu7ÆBb33c¶'&²b33c¶ÒÂgV÷C²gV÷C² f÷"b33c¶¢ÒFòT&÷VæBb33c¶çVÖ&W"Ò  b33c¶WVFöâf×³Òb33c¶çVÖ&W%²b33c¶¥Òf×²b33c¶FF²b33c¶¥Ð æW@ b33c¶WVFöâf×³Òb33c¶çVÖ&W%µT&÷VæBb33c¶çVÖ&W"ÒÐ bWV7WFRb33c¶WVFöâÒb33cµ6öÇWFöåFôfæBFVâb33c·6öÇWFöç2f×³Òb33c¶WVFöâf×²gV÷C²ÒgV÷C²f×²WV7WFRb33c¶WVFöâf×²5\$Ä` æW@ bb33c·6öÇWFöç2ÒgV÷C²gV÷C²FVà b33c·&W2ÒgV÷C²gV÷C° f÷"b33c·BÒFòT&÷VæBb33c¶fÆTÆæT'&Ò b33c·&W2f×³Òb33c¶fÆTÆæT'&²b33c·EÒf×²gV÷C²ÂgV÷C° æW@ b33c·&W2Ò7G&æuG&Õ&vBb33c·&W2Âf×²gV÷C²æöæRf÷VæBgV÷C° ôFV'Vt÷WBb33c·&W2 VÇ6P ôFV'Vt÷WB5\$Äbf×²b33c·6öÇWFöç2 VæD`¤VæDgVæ2³ÓÒfwC´6öÖ&æFöäç0 ¤gVæ2ôÆÅô6öÖ&æFöç2b33c·57G&ær FÒb33c¶ b7G&ætÆVâb33c·57G&ærÒT&÷VæBb33c¶çVÖ&W"Ò"FVà b33c·4öÆBf×³Òb33c·57G&ærf×²gV÷C·ÂgV÷C° &WGW&à VæD` f÷"b33c¶ÒFò@ ôÆÅô6öÖ&æFöç2b33c·57G&ærf×²b33c´÷W&F÷%²b33c¶Ò æW@¤VæDgVæ2³ÓÒfwCµôÆÅô6öÖ&æFöç0```

##### Share on other sites

Yes, it's this ! Very thanks !

Can we note all the possibilities for the calculations to find the possible results ?

for example the result 22 with the numbers 4, 2, 10, 6

Solution 1 : 4 2 10 6

Solution 2 : 2 * 10 6-4

x solution : ...

And give a clue to the method used.

for example if the calculation is in the form * + - / then index 1

if the calculation is in the form * - / + while index 2

etc...

But this is automatic unless one is obliged to return all possibilities, all conditions manually ?

thank you

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

##### Share on other sites

even if it takes a long time, it's not serious, but I would note in the file all the possibilities for computing the result.

Thank you

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

## Create an account

Register a new account