## Recommended Posts

I have a list of over 10 numbers and want to find out how to find the percent of the number.

What I need to do is find the top 2% percent and work my way down and make the top 2% of the numbers equal to number 11 and continue, all the numbers will be between -12 and 12.

11 = 2% >>> 98.0001 - 100%

10 = 4% >>> 94.0001% - 98%

9 = 15% >>> 79.0001% - 94%

8 = 20% >>> 59.0001% - 79%

7 = 20% >>> 39.0001% - 59%

6 = 15% >>> 24.0001% - 39%

5 = 15% >>> 9.0001% - 24%

4 = 7% >>> 2.0001% - 9%

3 = 2% >>> .0000% - 2%

What I have so far, but can not get my head around how to solve the math part.

```#include <Array.au3>

\$iPlayer = 60
\$iOpenent = 0
\$iGames = 5
Dim \$aPlayers[100] ; could be any number from 10 to 10000

For \$i = 0 to UBound(\$aPlayers) -1
\$aPlayers[\$i] = Random(-12,12)
\$aPlayers[\$i] = Round(\$aPlayers[\$i],4)
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Next

_ArraySort(\$aPlayers)
ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF)

For \$i = 0 to UBound(\$aPlayers) -1
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] &  @CRLF)
Next```

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

Something like this?

```#include <Array.au3>

\$iPlayer = 60
\$iOpenent = 0
\$iGames = 5
Dim \$aPlayers[100] ; could be any number from 10 to 10000
\$highest = 0
For \$i = 0 To UBound(\$aPlayers) - 1
\$aPlayers[\$i] = Random(-12, 12)
\$aPlayers[\$i] = Round(\$aPlayers[\$i], 4)
If \$aPlayers[\$i] > \$highest Then
\$highest = \$aPlayers[\$i]
EndIf

ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Next

_ArraySort(\$aPlayers)
ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF)

For \$i = 0 To UBound(\$aPlayers) - 1
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Select
Case \$aPlayers[\$i] > 0.98 * \$highest
\$aPlayers[\$i] = 11
Case \$aPlayers[\$i] > 0.94 * \$highest
\$aPlayers[\$i] = 10
;etc

EndSelect

Next```

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

##### Share on other sites

That does not work, as there should be a number for each value and each value should have the number of percent using 100 players as the test. Do you understand what I am saying?

```#include <Array.au3>

\$iPlayer = 60
\$iOpenent = 0
\$iGames = 5
Dim \$aPlayers[100] ; could be any number from 10 to 10000
\$highest = 0
For \$i = 0 To UBound(\$aPlayers) - 1
\$aPlayers[\$i] = Random(-12, 12)
\$aPlayers[\$i] = Round(\$aPlayers[\$i], 4)
If \$aPlayers[\$i] > \$highest Then
\$highest = \$aPlayers[\$i]
EndIf

ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Next

_ArraySort(\$aPlayers)
ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF)

For \$i = 0 To UBound(\$aPlayers) - 1

Select
Case \$aPlayers[\$i] > 0.98 * \$highest
\$aPlayers[\$i] = 11
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.94 * \$highest
\$aPlayers[\$i] = 10
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.79 * \$highest
\$aPlayers[\$i] = 9
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.59 * \$highest
\$aPlayers[\$i] = 8
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.39 * \$highest
\$aPlayers[\$i] = 7
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.24 * \$highest
\$aPlayers[\$i] = 6
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.9 * \$highest
\$aPlayers[\$i] = 5
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.2 * \$highest
\$aPlayers[\$i] = 4
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case Else
\$aPlayers[\$i] = 3
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
EndSelect

Next```

EDIT - changed values for 2 lowest numbers - but still same issue

11 should have 2 numbers only

10 should have 4 numbers only

9 should have 15 numbers only

ECT.

EDIT fixed the value for 10

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

That does not work, as there should be a number for each value and each value should have the number of percent using 100 players as the test. Do you understand what I am saying?

No.

I would be very impressed if anyone could make sense of that

I wasn't sure what you meant in your first post but after your second post I'm certain that I don't understand. But don't you think that it is really what your problem is? Perhaps if you could generate a clear description of what is needed then you could solve it yourself.

Anyway, you need to give a much clearer, and probably longer, explanation of what you want for me to be able to help.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

##### Share on other sites

No.

I would be very impressed if anyone could make sense of that

I wasn't sure what you meant in your first post but after your second post I'm certain that I don't understand. But don't you think that it is really what your problem is? Perhaps if you could generate a clear description of what is needed then you could solve it yourself.

Anyway, you need to give a much clearer, and probably longer, explanation of what you want for me to be able to help.

Sorry for not being able to explain in words, but here it goes:

If there are 100 players and each is given a ranking of 11,10,9,8,7,6,5,4,3 there has to be a given percent of them that has that number. 100 players is what I am using for the test.

11 should have 2 numbers only -- for 2%

10 should have 4 numbers only -- for 4%

9 should have 15 numbers only -- for 15%

ECT.

5 should have 15 numbers only -- for 15%

4 should have 7 numbers only -- for 7%

3 should have 2 numbers only -- for 2%

EDIT fixed the number for value 10

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

What is the logic here?

11 -> 2

10 -> 4

9 -> 15

8 -> 20

7 -> 20

6 -> 15

5 -> 15

4 -> 7

3 -> 2

Edit:

If there are 100 players and each is given a ranking of 11,10,9,8,7,6,5,4,3 there has to be a given percent of them that has that number

Why? Isn't it just random? Like how is it assigned, is it distributed evenly? Edited by Manadar

##### Share on other sites

What is the logic here?

11 -> 2

10 -> 4

9 -> 15

8 -> 20

7 -> 20

6 -> 15

5 -> 15

4 -> 7

3 -> 2

Edit:

Why? Isn't it just random? Like how is it assigned, is it distributed evenly?

It is distributed by the value of the percent on the right hand side. The TOP 2% of the field get a value of 11, the next 4% get the value of 10, the next 15% get the value of 9, and so on. The percent may change, but that this is my starting point.

The math is what is getting me - thanks for ALL your help.

EDIT - there should be more 7 and 8's in the total field as that is the average player.

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

It is distributed by the value of the percent on the right hand side. The TOP 2% of the field get a value of 11, the next 4% get the value of 10, the next 15% get the value of 9, and so on. The percent may change, but that this is my starting point.

The math is what is getting me - thanks for ALL your help.

EDIT - there should be more 7 and 8's in the total field as that is the average player.

That is exactly what my script did I thought.

There are some players.

They all get a score somehow.

The players who are in the top 2% of the highest scores have the value 11 given to them and so on.

Say the top score is 100 for simplicity. Say there are 100 players as you said. Say 8 players get the score of 98.001 or more. What value is given to them? Not 11?There are 8% of the players that have the number 11 so where is that 8% to be stored?

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

##### Share on other sites

Is it something like this?

```#include <Array.au3>

\$iPlayer = 60
\$iOpenent = 0
\$iGames = 5
Dim \$aPlayers[100] ; could be any number from 10 to 10000
\$highest = 0
For \$i = 0 To UBound(\$aPlayers) - 1
\$aPlayers[\$i] = Random(-12, 12)
\$aPlayers[\$i] = Round(\$aPlayers[\$i], 4)
If \$aPlayers[\$i] > \$highest Then
\$highest = \$aPlayers[\$i]
EndIf

ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Next

_ArraySort(\$aPlayers)
ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF)
For \$i = 0 To UBound(\$aPlayers) - 1

Select
Case \$aPlayers[\$i] > 0.98 * \$highest
\$aPlayers[\$i] = 11
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.94 * \$highest
\$aPlayers[\$i] = 10
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.79 * \$highest
\$aPlayers[\$i] = 9
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.59 * \$highest
\$aPlayers[\$i] = 8
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.39 * \$highest
\$aPlayers[\$i] = 7
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.24 * \$highest
\$aPlayers[\$i] = 6
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.9 * \$highest
\$aPlayers[\$i] = 5
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.2 * \$highest
\$aPlayers[\$i] = 4
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case Else
\$aPlayers[\$i] = 3
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
EndSelect

Next

For \$n = 1 to 9
Next

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

##### Share on other sites

That is exactly what my script did I thought.

There are some players.

They all get a score somehow.

The players who are in the top 2% of the highest scores have the value 11 given to them and so on.

Say the top score is 100 for simplicity. Say there are 100 players as you said. Say 8 players get the score of 98.001 or more. What value is given to them? Not 11?There are 8% of the players that have the number 11 so where is that 8% to be stored?

GOOD QUESTION -

See why I come here for my math questions - you did answer my question! But when I run your code a number of times, I do not get any values for some of the values (11,10,9--5,4,3) and should there not be a value for each of them? Maybe my logic is impaired - I could be drunk and not know it.

In your example of 8 players having the value of 98.0001 or above - only the very top 2 scores will have the value of 11 - of course if each of the 8 players have the same score i.e. 11.0050 and no one has a higher score then each player would have to have a value of 11. Maybe that is what is taking the numbers from the rest of the values, but I am not seeing two percents equal to each other?

```#include <Array.au3>

\$iPlayer = 60
\$iOpenent = 0
\$iGames = 5
Dim \$aPlayers[100] ; could be any number from 10 to 10000
\$highest = 0
For \$i = 0 To UBound(\$aPlayers) - 1
\$aPlayers[\$i] = Random(-12, 12)
\$aPlayers[\$i] = Round(\$aPlayers[\$i], 4)
If \$aPlayers[\$i] > \$highest Then
\$highest = \$aPlayers[\$i]
EndIf

ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Next

_ArraySort(\$aPlayers)
ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF)

For \$i = 0 To UBound(\$aPlayers) - 1
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Next

For \$i = 0 To UBound(\$aPlayers) - 1

Select
Case \$aPlayers[\$i] > 0.98 * \$highest
\$aPlayers[\$i] = 11
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.94 * \$highest
\$aPlayers[\$i] = 10
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.79 * \$highest
\$aPlayers[\$i] = 9
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.59 * \$highest
\$aPlayers[\$i] = 8
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.39 * \$highest
\$aPlayers[\$i] = 7
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.24 * \$highest
\$aPlayers[\$i] = 6
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.09 * \$highest
\$aPlayers[\$i] = 5
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.02 * \$highest
\$aPlayers[\$i] = 4
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case Else
\$aPlayers[\$i] = 3
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
EndSelect

Next```
Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

Is it something like this?

```#include <Array.au3>

\$iPlayer = 60
\$iOpenent = 0
\$iGames = 5
Dim \$aPlayers[100] ; could be any number from 10 to 10000
\$highest = 0
For \$i = 0 To UBound(\$aPlayers) - 1
\$aPlayers[\$i] = Random(-12, 12)
\$aPlayers[\$i] = Round(\$aPlayers[\$i], 4)
If \$aPlayers[\$i] > \$highest Then
\$highest = \$aPlayers[\$i]
EndIf

ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Next

_ArraySort(\$aPlayers)
ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF)
For \$i = 0 To UBound(\$aPlayers) - 1

Select
Case \$aPlayers[\$i] > 0.98 * \$highest
\$aPlayers[\$i] = 11
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.94 * \$highest
\$aPlayers[\$i] = 10
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.79 * \$highest
\$aPlayers[\$i] = 9
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.59 * \$highest
\$aPlayers[\$i] = 8
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.39 * \$highest
\$aPlayers[\$i] = 7
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.24 * \$highest
\$aPlayers[\$i] = 6
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.9 * \$highest
\$aPlayers[\$i] = 5
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case \$aPlayers[\$i] > 0.2 * \$highest
\$aPlayers[\$i] = 4
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Case Else
\$aPlayers[\$i] = 3
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
EndSelect

Next

For \$n = 1 to 9
Next

No that does not seem to work either - I am working on the logic, but I have to drive home - talk to later.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

OK - I have given it all I got and have come close, but cannot get it to exactly where I want it.

As you can see from the console output - the values are transversed - CAN ANY HELP?

```#include <Array.au3>
#test = 0
\$highest = 0
Dim \$aPlayers[101] ; could be any number from 10 to 10000
Dim \$aRank[10] = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3]
Dim \$aPercent[10] = [100, 2, 4, 15, 20, 20, 15, 15, 7, 2]
Dim \$aTempPercent[10]

For \$n = 1 To UBound(\$aPercent) - 1
\$aPercent[0] += \$aPercent[\$n]
Next
If \$aPercent[0] <> 200 Then
MsgBox('', 'ERROR', 'Total value of percent does not equal 100%')
Else
\$aPercent[0] = 100
EndIf
;subtract the value from 100 and give to temp array
For \$n = 1 To UBound(\$aPercent) - 1
\$aPercent[0] -= \$aPercent[\$n]
\$aTempPercent[\$n] = \$aPercent[0]
Next

; TESTING ONLY - Values to come from INI file
For \$i = 0 To UBound(\$aPlayers) - 1
;ConsoleWrite(UBound(\$aPlayers) & @CRLF)
\$aPlayers[\$i] = Random(-12, 12) ; change this for testing - min = 11
\$aPlayers[\$i] = Round(\$aPlayers[\$i], 4)

;MsgBox('','',mod (UBound(\$aPlayers),100))
If \$aPlayers[\$i] > \$highest Then
\$highest = \$aPlayers[\$i]
EndIf
;ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF & @CRLF)
Next

;#cs
If Mod(UBound(\$aPlayers), 100) <> 100 Then
;If Mod(UBound(\$aPlayers), 100) <> 0 Then _ArrayAdd(\$aPlayers, Round(Random(-12,12),4))
While Mod(UBound(\$aPlayers), 100) <> 0
;MsgBox('','Mod(UBound(\$aPlayers),100) <> 100',Mod(UBound(\$aPlayers),100))
;_ArrayDisplay(\$aPlayers, 'before')
;;_ArrayDisplay(\$aPlayers, 'after')
;MsgBox('','',UBound(\$aPlayers))
WEnd

;MsgBox('','Mod(UBound(\$aPlayers),100) <> 100',Mod(UBound(\$aPlayers),100) <> 100)
EndIf
;#ce    If \$aPlayers[\$i] > \$highest Then
\$highest = \$aPlayers[\$i]
EndIf
;ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF & @CRLF)
Next

_ArraySort(\$aPlayers)
_ArrayDisplay(\$aPlayers)
MsgBox('','',UBound(\$aPlayers))
;ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF)

#cs
For \$i = 0 To UBound(\$aPlayers) - 1
ConsoleWrite(\$i & '     ' & \$aPlayers[\$i] & @CRLF)
Next
ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF)
#ce
For \$n = 1 To 9
Next

For \$i = 0 To UBound(\$aPlayers) - 1

Select
Case \$aPlayers[\$i] > \$aTempPercent[1] / 100 * \$highest Or UBound(\$aPlayers) - \$aPercent[1] >= \$aTempPercent[1] And \$aSpread[1][1] <> \$aPercent[1] * UBound(\$aPlayers) / 100 ;Or \$aSpread[1][1] < \$aPercent[1] * UBound(\$aPlayers) / 100;.98 -->> 11 --> 2
;If \$test =  1 then MsgBox('', \$aTempPercent[1] / 100 * \$highest,\$aPlayers[\$i])

ConsoleWrite(\$i & ' ' & \$aTempPercent[1] & ' ' & \$aPlayers[\$i])
\$aPlayers[\$i] = 11
ConsoleWrite(' Player Rank = ' & \$aPlayers[\$i] & @CRLF)

Case \$aPlayers[\$i] > \$aTempPercent[2] / 100 * \$highest Or UBound(\$aPlayers) - \$aPercent[2] >= \$aTempPercent[2] And \$aSpread[2][1] <> \$aPercent[2] * UBound(\$aPlayers) / 100 ;.94 --<< 10 --> 4
;If \$test =  1 then MsgBox('', \$aPercent[2], 100 * .94)

ConsoleWrite(\$i & ' ' & \$aTempPercent[2] & ' ' & \$aPlayers[\$i])
\$aPlayers[\$i] = 10
ConsoleWrite(' Player Rank = ' & \$aPlayers[\$i] & @CRLF)

Case \$aPlayers[\$i] > \$aTempPercent[3] / 100 * \$highest Or UBound(\$aPlayers) - \$aPercent[3] >= \$aTempPercent[3] And \$aSpread[3][1] <> \$aPercent[3] * UBound(\$aPlayers) / 100 ;.79 -->> 9 --> 15
;If \$test =  1 then MsgBox('', \$aPercent[3], 100 * .79)

ConsoleWrite(\$i & ' ' & \$aTempPercent[3] & ' ' & \$aPlayers[\$i])
\$aPlayers[\$i] = 9
ConsoleWrite(' Player Rank = ' & \$aPlayers[\$i] & @CRLF)

Case \$aPlayers[\$i] > \$aTempPercent[4] / 100 * \$highest Or UBound(\$aPlayers) - \$aPercent[4] >= \$aTempPercent[4] And \$aSpread[4][1] <> \$aPercent[4] * UBound(\$aPlayers) / 100 ;.59 -->> 8 --> 20
;If \$test =  1 then MsgBox('', \$aPercent[4], 100 * .59)

ConsoleWrite(\$i & ' ' & \$aTempPercent[4] & ' ' & \$aPlayers[\$i])
\$aPlayers[\$i] = 8
ConsoleWrite(' Player Rank = ' & \$aPlayers[\$i] & @CRLF)

Case \$aPlayers[\$i] > \$aTempPercent[5] / 100 * \$highest Or UBound(\$aPlayers) - \$aPercent[5] >= \$aTempPercent[5] And \$aSpread[5][1] <> \$aPercent[5] * UBound(\$aPlayers) / 100 ;.39 -->> 7 --> 20
;If \$test =  1 then MsgBox('', \$aPercent[5], 100 * .39)

ConsoleWrite(\$i & ' ' & \$aTempPercent[5] & ' ' & \$aPlayers[\$i])
\$aPlayers[\$i] = 7
ConsoleWrite(' Player Rank = ' & \$aPlayers[\$i] & @CRLF)

Case \$aPlayers[\$i] > \$aTempPercent[6] / 100 * \$highest Or UBound(\$aPlayers) - \$aPercent[6] >= \$aTempPercent[6] And \$aSpread[6][1] <> \$aPercent[6] * UBound(\$aPlayers) / 100 ;.24 -0->> 6 --> 15
;If \$test =  1 then MsgBox('', \$aPercent[6], 100 * .24)

ConsoleWrite(\$i & ' ' & \$aTempPercent[6] & ' ' & \$aPlayers[\$i])
\$aPlayers[\$i] = 6
ConsoleWrite(' Player Rank = ' & \$aPlayers[\$i] & @CRLF)

Case \$aPlayers[\$i] > \$aTempPercent[7] / 100 * \$highest Or UBound(\$aPlayers) - \$aPercent[7] >= \$aTempPercent[7] And \$aSpread[7][1] <> \$aPercent[7] * UBound(\$aPlayers) / 100 ;.09 -->> 5 --> 15
;If \$test =  1 then MsgBox('', \$aPercent[7], 100 * .39)

ConsoleWrite(\$i & ' ' & \$aTempPercent[7] & ' ' & \$aPlayers[\$i])
\$aPlayers[\$i] = 5
ConsoleWrite(' Player Rank = ' & \$aPlayers[\$i] & @CRLF)

Case \$aPlayers[\$i] > \$aTempPercent[8] / 100 * \$highest Or UBound(\$aPlayers) - \$aPercent[8] >= \$aTempPercent[8] And \$aSpread[8][1] <> \$aPercent[8] * UBound(\$aPlayers) / 100 ;.02 -->> 4 --> 7
;If \$test =  1 then MsgBox('', \$aPercent[8], 100 * .39)

ConsoleWrite(\$i & ' ' & \$aTempPercent[8] & ' ' & \$aPlayers[\$i])
\$aPlayers[\$i] = 4
ConsoleWrite('     Player Rank = ' & \$aPlayers[\$i] & @CRLF)

Case \$aPlayers[\$i] > \$aTempPercent[9] / 100 * \$highest Or UBound(\$aPlayers) - \$aPercent[9] >= \$aTempPercent[9] And \$aSpread[9][1] <> \$aPercent[9] * UBound(\$aPlayers) / 100 ;.0 -->> 3 --> 2
;If \$test =  1 then MsgBox('', \$aPercent[9], 100 * .39)

ConsoleWrite(\$i & ' ' & \$aTempPercent[9] & ' ' & \$aPlayers[\$i])
\$aPlayers[\$i] = 3
ConsoleWrite('     Player Rank = ' & \$aPlayers[\$i] & @CRLF)

Case Else
ConsoleWrite('FAILED     ' &   \$aPlayers[\$i] & @CRLF)
;Exit
EndSelect

Next
;#cs
For \$n = 1 To 9
Next

;#ce```
EDIT - CHANGED code Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

What's missing is a clear explanation of what you're trying to do and if you think your code comes close then you must know what you're aiming for in which case it would be helpful to know what it is.

You start with \$spread set to the level number for a certain score. Then you add the number of players with scores in that range. Why?

Then you do this-

`\$aSpread[\$n][1] = \$aSpread[\$n][1] * 100 / UBound(\$aPlayers) * UBound(\$aPlayers) / 100`

which is the same

`\$aSpread[\$n][1] = \$aSpread[\$n][1] * 1`

Are you still drunk?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

##### Share on other sites

OK - it is Saturday and after 2PM so yea I am getting there = DRUNK

I guess that line does not make any sence? It did in earlier versions - sorry, but if you take that line out, I still have the same issue.

OK - try to get this on paper again.

What I am looking for is a list of numbers ranging from -12 to 12 and with that list distributing it out evenly with the percents already mentioned. Each of the numbers will get a value and that value ranges from 11 through 3. The problem I had with earlier versions is that if the number was not in a hundred format - it would break (hundred like - 1200, 200, 500, 10000). If the number was less than a hundred format I had to add to it to get the formula to work i.e. if the total players was 91 I had to add 9 to the array, for it to distribute with the percents that I want, like wise if the total numbers being evaluated(sp)was total was 101 I had to add to the array 99 players for the forumla to work. I would not like to have to do this, but it seems in my MATH it was a must. If anyone can show me another way of grabbing each player and giving them a value of 11 through 3 (11 being the highest and 3 being the lowest) I would thank you from the bottom of my heart.

Again the values needed

number of payers =100

then the following must be true

2 players will get 11

4 players will get 10

15 players will get 9

20 players will get 8

20 players will get 7

15 players will get 6

15 players will get 5

7 players will get 4

2 players will get 3

Total players should equal 2+4+15+20+20+15+15+7+2 = 100

So it the value was 101 then there should be 3+4+15+20+20+15+15+7+2 = 101

So it the value was 102 then there should be 3+5+15+20+20+15+15+7+2 = 102

So it the value was 103 then there should be 3+5+16+20+20+15+15+7+2 = 103

So it the value was 104 then there should be 3+5+16+21+20+15+15+7+2 = 104

So it the value was 105 then there should be 3+5+16+21+21+15+15+7+2 = 105

So it the value was 106 then there should be 3+5+16+21+21+16+15+7+2 = 106

So it the value was 107 then there should be 3+5+16+21+21+16+16+7+2 = 107

and so on - I hope all the numbers are correct

I hope that makes it clear as mud -

EDIT Had to coreect the numbers

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

I believe your problem is still poorly defined. In your latest post, if players keep adding in the way you've described you'll eventually get a flat distribution (no bell curve) for large n. I'm fairly certain this is not what you want.

Whenever I see all those "Cases" I just know there is a more elegant solution - I often encounter these situations - mainly in Excel. I would highly recommend trying to solve the problem in Excel first - saves so much time.

I believe this is what you are looking for. There is a rounding error in the method. I've included a rudimentary way to deal with it. Also your inverted results would be because the array needs to be sorted descending.

```#include <Array.au3>
Dim \$aPlayers[101] ; could be any number from 10 to 10000
Dim \$aRank[10] = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3]
Dim \$aPercent[10] = [100, 2, 4, 15, 20, 20, 15, 15, 7, 2]
Dim \$aTempPercent[10]

; This will give the number of players in each rank
; following the same distribution as the 100 base case.
\$Players = UBound(\$aPlayers)
\$aTempPercent[0] = 0
For \$i = 1 to 9
\$aTempPercent[\$i] = Round(\$aPercent[\$i]*\$Players/100,0) ;
\$aTempPercent[0] += \$aTempPercent[\$i]
Next

; If there is a difference due to rounding, then add the diff to the median
\$Diff = \$Players - \$aTempPercent[0]
If \$Diff <> 0 Then
\$aTempPercent[5] += \$Diff
\$aTempPercent[0] += \$Diff
EndIf

_ArrayDisplay(\$aTempPercent)

; give each player a score
For \$i = 0 To UBound(\$aPlayers) - 1
\$aPlayers[\$i] = Round(Random(-12, 12),4)
Next

; sort scores in descending order
_ArraySort(\$aPlayers,1)
_ArrayDisplay(\$aPlayers)

; now get rid of those "cases"!
\$i = 0
\$first=0
\$last=0
For \$k = 1 To 9 ; for each rank in \$aTempPercent...
\$first=\$last+1 ; dertimine start of "block" - actually just end of last block + 1
\$last+=\$aTempPercent[\$k] ; determine end of "block" - actually cumulative histogram of \$aTempPercent
For \$j = \$first To \$last
\$aPlayers[\$i]=\$aRank[\$k]
\$i += 1
Next
Next

; our beautiful results
_ArrayDisplay(\$aPlayers)

Exit```

##### Share on other sites

I wish that I was able to explain it better. Here is another attempt to explain better.

This is for my pool league - we are changing the way people are handicapped players, with that said, the best players in the league are going to be 11's and the worst players will be given a rank of 3. So there is always going to be a 11 and a 3 on the ranking, as there will always be the best player and the worst player - the points given for each player -12 through 12 are received by the difference between the balls sunk for the winner and looser divided by the number of games played (the value given to the 8 ball is 3 points and if the person were to hit the 8 on the break or were to run the table then that person would receive the top score of 12). So if a person played 5 games and scored a total of 60 points then that player would be the best player and given the rank of 11 as he would have scored 12 in his match (60 - 0) / 5 and his appointment would have scored -12 and he would be given the rank of 3 with a score of -12.

So as you can see there is always going to be a 12 and a 3 in the league. With your code if there were only 10 players then there should be a value given for each of the ranks, 3 being the worst player and 11 being the best player.

That being said, I love how you were able to make the code so short. But it is so short that I have spent almost 2 days trying to figure it out - - can you help me anymore?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

##### Share on other sites

This is a fantastic intellectual exercise and I'm not surprised it's taken days to solve.

It seems the only remaining problem is that the model is not valid for small n. You knew this already right? So what do you suggest? What about your rule "only the top 2% get 11"?

It would be good if you could finish it off to at least show us that is was worth our time. You said this was a “maths” problem. The maths has been done. You only need to do two more things:

a ) decide which n (number of players) below which the model is no longer valid.

b ) implement the code to deal with that situation.

One more thing, you probably need to implement something to deal with ties (lots of players with same raw score). Only important at the border where you have to decide who goes up (a rank) and who stays down even though they both have the same score.

QED

##### Share on other sites

@QED - thanks for all your help - I think I am going to stick to your code for now, until I can think of a way to work with number of players < 25. I will also have to work with the ties, but I got a good idea how to avoid them.

Again thanks for everyones help.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go."

"Everybody catches up with everyone, eventually"

"As you teach others, you are really teaching yourself."

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace \$ghGDIPDll with \$__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

# Ternary operator

## Create an account

Register a new account

×

• Wiki

• Back

• Git