Help - Search - Members - Calendar
Full Version: Sorting a list of numbers (using max, ceil)
AC Tools Everything Macro > AC Tool Macros > Macro Development
Sheeple
I have a bit of a problem. I have a list of numbers (RGBRed) and im trying to find the odd one out. For instance.

c1 = 51
c2 = 50
c3 = 49
c4 = 52
c5 = 51
c6 = 52
c7 = 44

Theres always 7 numbers, and theres always 1 odd color.

I was thinking of taking the average, then taking the absolute value of the differnce of the numbers. The one with the highest differnce should be the odd one out most of the time (as its only the red in the pixel). How would I use the max or the ceil command to find the farthest off of the number so I can single it out?

Or if anyone has any other ideas to find the odd color out, id be greatful.

Ahk
A dataset would work, I threw this together and it seems to work:

CODE
Constants
  c1 = 51
  c2 = 50
  c3 = 49
  c4 = 52
  c5 = 51
  c6 = 52
  c7 = 44
  
  NumberOfValues = 7
  TotalValues = 0
  AverageValues = 0
  AbsoluteTemp = 0
  MaxValue = 0
  MaxRecord = 0
End
Constructs
  lstValues = List
End

Procedure Add Using Value
  TimeStamp Value $Value
  ListAdd lstValues, $Value
  Compute TotalValues = $Value + $TotalValues
End


Loop $NumberOfValues
  Call Add $c{loopno}
End
Compute AverageValues = Int($TotalValues / $NumberOfValues)


Loop $NumberOfValues
    SetConst AbsoluteTemp = lstValues[{loopno}] //couldn't get this to work in forumula below without setconst first
  Compute AbsoluteTemp = Abs($AbsoluteTemp - $AverageValues)
    TimeStamp Absolute difference between lstValues[{loopno}] and $AverageValues is $AbsoluteTemp
    If $AbsoluteTemp > $MaxValue
      SetConst MaxRecord = {loopno}
      SetConst MaxValue = $AbsoluteTemp
    End
End

TimeStamp MaxRecord $MaxRecord
TimeStamp MaxValue $MaxValue
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.