User Tag List

Results 1 to 4 of 4

Thread: Count number of times a number appears

  1. #1
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export ModuleMac Export Module
    Hydra's Avatar
    Join Date
    May 2012
    Posts
    141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Count number of times a number appears

    If i have a set of numbers stored in some alterables values, how would I loop through the values and count the number of times each unique number appears?
    For example:
    Alterable value 0 = 0
    Alterable value 1 = 1
    Alterable value 2 = 1000
    Alterable value 3 = 500
    Alterable value 4 = 1000

    I would want my program to output that there is one 0, one 1, one 500, and two 1000s....

    Thanks!

  2. #2
    Clickteam Clickteam
    Simon's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    2,647
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Which platform do you want to do this on? Could you give a little more detail on what you are trying to achieve here at all? I can see how to do what you need, but it doesn't seem like a very efficient solution. Also, what is the range of potential numbers you will be testing for? Is there an upper limit, lower limit, only a set pool of values (such as 100, 200, 300 etc.)

  3. #3
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Francois's Avatar
    Join Date
    Jul 2006
    Location
    Montpellier, France
    Posts
    6,920
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    OK. Here is the method for 0, 1 and 2s

    Create a counter for 0, 1, 2s etc.

    -> Store the number in a string object, using the "Number to string" expression in the string object expression menu
    * Always
    - Set NumberVersionOfText$ to str$(Number)

    -> Do a fast loop (in the system object)
    * Always
    + Set "number of 0s" to 0
    + Set "number of 1s" to 0
    + Set "number of 2s" to 0
    + Start loop "Count" Len(String$("NumberInText)) (in the system object expression menu)

    * On loop "count"
    * Mid$(NumberVersionOfText, LoopIndex("Count"), 1) = "0"
    - Add 1 to "Number of 0s"

    * On loop "count"
    * Mid$(NumberVersionOfText, LoopIndex("Count"), 1) = "1"
    - Add 1 to "Number of 1s"

    * On loop "count"
    * Mid$(NumberVersionOfText, LoopIndex("Count"), 1) = "2"
    - Add 1 to "Number of 2s"

    This should work.

  4. #4
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For an arbitrary number of possibilities, I'd create a map (Named Variable Object or anything else that supports key-value pairs) and loop over the list once by using Get Alterable Value with Index N (I can't remember the exact expression):

    - Get the alterable value
    - Increment the value's key in the map by 1

    The map will hold the number of occurrences of each number. In the given example:

    Alterable value 0 = 0
    Alterable value 1 = 1
    Alterable value 2 = 1000
    Alterable value 3 = 500
    Alterable value 4 = 1000

    Loop: Gets 0. Map now contains:
    0=1

    Loop: Gets 1. Map now contains:
    0=1
    1=1

    Loop: Gets 1000. Map now contains:
    0=1
    1=1
    1000=1

    Loop: Gets 500. Map now contains:
    0=1
    1=1
    1000=1
    500=1

    Loop: Gets 1000. Map now contains:
    0=1
    1=1
    1000=2
    500=1

    Now loop over each key in the map, and you have the number of occurrences of that number.

Similar Threads

  1. Count number of Characters or Digits?
    By King_Cool in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 4th November 2012, 12:27 AM
  2. way to count number of groups in INI+ ?
    By BrashMonkey in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 13th October 2009, 02:05 AM
  3. Count the number of Alterable strings
    By Attan in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 3rd October 2007, 10:32 PM
  4. Making animation play random number of times....
    By mussashimits in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 18th July 2007, 01:37 AM
  5. Animate a Random number of times
    By Sarah in forum File Archive
    Replies: 0
    Last Post: 17th July 2007, 08:20 PM

Posting Permissions

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