Results 1 to 25 of 25

Thread: Averaging items in an array

  1. #1
    Join Date
    Feb 2007
    Posts
    849
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Averaging items in an array

    Is there a function that already does this?
    I can't seem to find one.

    If not, surely it'd be a case of a loop and adding all the values, dividing by the number of items?
    ________________________________________
    14:19 < cycrosism> I wonder what she would have done without it
    14:19 < cycrosism> without me*
    Cycrosism is now an it.
    Quote Originally Posted by Dervish View Post
    /Facedesk.

  2. #2
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    I don't think there is a function for this, but its just like what you said, add em all in a loop and divide by the number of items.

  3. #3
    Join Date
    Dec 2010
    Posts
    431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Averaging what exactly..?

  4. #4
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

  5. #5
    Join Date
    Dec 2010
    Posts
    431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Averaging "items" in an array.
    I was thinking he wanted to use inventory items to average something, was confused.

  6. #6
    Join Date
    Feb 2007
    Posts
    849
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Generally each number in an Array is an item (outside of Simba etc anyway).

    I just have an Array of Tokkul Gained per Fight Cave Run, and thought it would be nice to show on average how much is being gained!
    ________________________________________
    14:19 < cycrosism> I wonder what she would have done without it
    14:19 < cycrosism> without me*
    Cycrosism is now an it.
    Quote Originally Posted by Dervish View Post
    /Facedesk.

  7. #7
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by 05hartor View Post
    Generally each number in an Array is an item (outside of Simba etc anyway).

    I just have an Array of Tokkul Gained per Fight Cave Run, and thought it would be nice to show on average how much is being gained!
    You don't need an array to do that, you can just use two variables.

  8. #8
    Join Date
    Dec 2010
    Posts
    431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by 05hartor View Post
    Generally each number in an Array is an item (outside of Simba etc anyway).

    I just have an Array of Tokkul Gained per Fight Cave Run, and thought it would be nice to show on average how much is being gained!
    You increase the array one index each time you finish the cave?

    All you'd have to do is...

    SCAR Code:
    function AverageOutArray(const TheArray: TIntegerArray): Extended;
    var
      i, l, n: Integer;
    begin
      l := Length(TheArray);
      for i := 0 to l - 1 do
        n := n + TheArray[i];
      Result := n / l;
    end;
    Last edited by Train; 02-27-2011 at 02:45 AM.

  9. #9
    Join Date
    Feb 2007
    Posts
    849
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Okay, So say i've had these values.
    [10,12,16]. That one variable would be 14 after averaging.
    Then on the next run I get 12.

    How would you get a proper average from that? Cause the averages of 10,12,16 and 12 isn't 13.
    That's what I was going to put. The maths seems about right, I could be wrong as the numbers are small..

    Is that how it's done?
    ________________________________________
    14:19 < cycrosism> I wonder what she would have done without it
    14:19 < cycrosism> without me*
    Cycrosism is now an it.
    Quote Originally Posted by Dervish View Post
    /Facedesk.

  10. #10
    Join Date
    Dec 2010
    Posts
    431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by 05hartor View Post
    That's what I was going to put. The maths seems about right, I could be wrong as the numbers are small..

    Is that how it's done?
    Excuse me? I do not comprehend (The quote).

  11. #11
    Join Date
    Feb 2007
    Posts
    849
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I was writing this before you posted that function, it was aimed at KingKong as he said you only need an array

    What does Extending a Function do?

    edit: Does it allow for decimals?
    ________________________________________
    14:19 < cycrosism> I wonder what she would have done without it
    14:19 < cycrosism> without me*
    Cycrosism is now an it.
    Quote Originally Posted by Dervish View Post
    /Facedesk.

  12. #12
    Join Date
    Dec 2010
    Posts
    431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Extended is decimals.
    If you want a solid number, change Extended to Integer and Result := n / l; to Result := Round(n / l);

  13. #13
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by 05hartor View Post
    I was writing this before you posted that function, it was aimed at KingKong as he said you only need an array

    What does Extending a Function do?

    edit: Does it allow for decimals?
    You mean decimals inside the arrays? then no.

  14. #14
    Join Date
    Feb 2007
    Posts
    849
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nah, it's an Integer array. Can you get extended arrays (or an array compatible with decimals? Curiosity (I don't need it)).

    Cheers Train, now my fight cave runner is only a bit away from being released!
    ________________________________________
    14:19 < cycrosism> I wonder what she would have done without it
    14:19 < cycrosism> without me*
    Cycrosism is now an it.
    Quote Originally Posted by Dervish View Post
    /Facedesk.

  15. #15
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    I'm super confused. What's with loops and what not? It's just the amount of tokkul divided by the amount of runs..

  16. #16
    Join Date
    Dec 2010
    Posts
    431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by 05hartor View Post
    Nah, it's an Integer array. Can you get extended arrays (or an array compatible with decimals? Curiosity (I don't need it)).

    Cheers Train, now my fight cave runner is only a bit away from being released!
    You have an integer array but the result may be an extended.
    Say you have 1 and 2, the function would give 1.5. An array of floats would be [var name]: array of Extended; (or TExtendedArray if it exists).

  17. #17
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by i luffs yeww View Post
    I'm super confused. What's with loops and what not? It's just the amount of tokkul divided by the amount of runs..
    thats what i was trying to say a few posts ago.

  18. #18
    Join Date
    Feb 2007
    Posts
    849
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It's not.
    Cause people might start (like I did), with Tokkul in their inventory!

    Say they use it for 10 hours, leave it for a day and then leave it for another 10 hours, They will think that they'll be getting twice as much as they are actually getting, and an extra 4 lines of code prevents this!
    ________________________________________
    14:19 < cycrosism> I wonder what she would have done without it
    14:19 < cycrosism> without me*
    Cycrosism is now an it.
    Quote Originally Posted by Dervish View Post
    /Facedesk.

  19. #19
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    StartTokkul - EndTokkul == TokkulGained.


  20. #20
    Join Date
    Feb 2006
    Location
    Canada
    Posts
    2,254
    Mentioned
    21 Post(s)
    Quoted
    238 Post(s)

    Default

    Check if theres tokkul in the inv, then put that number in a var and subtract it from your gained then divide by runs to find avg.

  21. #21
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by 05hartor View Post
    Is there a function that already does this?
    I can't seem to find one.

    If not, surely it'd be a case of a loop and adding all the values, dividing by the number of items?
    Yes, there is. Under function list, TPA -> AverageTIA.

  22. #22
    Join Date
    Feb 2007
    Posts
    849
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    See, this is why I shouldn't be so tired whilst coding.
    Now I feel silly

    Oh well, it's nice to have the array! :3

    I was considering trying a wave counter, and producing a graph of some sort..

    1st run = 100 tokkul, wave 2
    2nd run = 200 tokkul, wave 4

    etc. Does Simba have graph capabilities? If not, can you make straight lines out of bitmaps to draw on the screen?

    edit: I think i'll stick with AverageTIA for now, but i'll keep the other average function as learning material!
    Last edited by HarryJames; 02-27-2011 at 03:04 AM.
    ________________________________________
    14:19 < cycrosism> I wonder what she would have done without it
    14:19 < cycrosism> without me*
    Cycrosism is now an it.
    Quote Originally Posted by Dervish View Post
    /Facedesk.

  23. #23
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    There's no real like.. graph functions, afaik, but it's not that difficult. Plot it and then draw lines from point to point.

  24. #24
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    You could try working off of this script for your graphing function, it looks challenging though.
    http://villavu.com/forum/showthread.php?t=36548

    Otherwise, just write a procedure that generates a text file report including the total Tokkul you recieved, the waves you ran, and the Tokkul you recieved from each wave on average. That would be a lot simpler imo.

  25. #25
    Join Date
    Feb 2007
    Posts
    849
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I have an idea for the graph.
    If not I'll put it as an option in the proggy!

    It wouldn't be too difficult to get the highest and lowest (rounded to the nearest 100) to help set the scale. Now we have the scales set, and the graph will be of a determined height/width so we can work out how high a value should go!

    Then it's just a case of a scatter graph I think.
    ________________________________________
    14:19 < cycrosism> I wonder what she would have done without it
    14:19 < cycrosism> without me*
    Cycrosism is now an it.
    Quote Originally Posted by Dervish View Post
    /Facedesk.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •