Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Checking number frequency

Author
Message
sneaky smith12
20
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 19th Oct 2010 17:52 Edited at: 19th Oct 2010 18:34
As the title suggests I'm trying to figure out how I would check the amount of times a number occurs from a file (numbers are presumed to be random). It would be helpful if the results were in numerical order as well.

I assume this would require at least two arrays, but I'm not sure? Also, can you declare an array without specifying dimensions?

My best guess would be to load all the numbers into an array:


And then make another array that where it's first dimension is equal to the data in the first array, and it's second dimension is the amount of times that number occurs in the data.

I don't have code for this, because I'm not sure how it would look. Any help?

If at first you dont succeed, LOWER YOUR STANDARDS.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Oct 2010 18:42
Are you just checking how often one number occurs? I am assuming not as otherwise it would be far simpler.

You can append to arrays using IanM's matrix utility plugin. That might help you...

I guess the main question is how many numbers are you looking for? And maybe why?

sneaky smith12
20
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 19th Oct 2010 20:27
Quote: "Are you just checking how often one number occurs? I am assuming not as otherwise it would be far simpler."


Yes. I just want to see how many times a single number occurs. The numbers are not integers though, so it probably would be best to compare them as strings.

Quote: "I guess the main question is how many numbers are you looking for? And maybe why?"

User defined amount of numbers (for my purposes about 3000). To make a histogram out of the data.

If at first you dont succeed, LOWER YOUR STANDARDS.
CSL
17
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: USA
Posted: 19th Oct 2010 21:23 Edited at: 19th Oct 2010 21:24
Quote: "can you declare an array without specifying dimensions?"
I would read the file, count the records and dimension based on the record count.

Quote: "I assume this would require at least two arrays, but I'm not sure?"

If you simply want to display the information, then one single array should be enough. It depends if further manipulation is necessary.

Quote: "It would be helpful if the results were in numerical order as well."
- The way I would approach it is.
-Read file, count number of records

- dimension array based on record count

- Sort array - There is BASIC sorting routine posted in the forums (Bubble Sort or Binary Sort)
http://forum.thegamecreators.com/?m=forum_view&t=9230&b=6

- Count occurrences of each number in the sorted array. When the number changes, print the total count. This is called a control break routine.
http://www.vb6.us/tutorials/generating-your-own-vb-reports-control-break-concepts

CSL
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Oct 2010 21:27
Read the file into an array while converting the strings to integers, sort it, then count the consecutive numbers. No need for further arrays if this is the entire scope of your problem.

Defining an array without specifying dimensions:


Growing an array:

You can add a single item at a time, but it'll be slow - if you have large number of numbers to read, grow the array 1000's at a time.

Sorting the array:


The above assumes that you use array item 0, and don't ignore it and start at 1. If you start at 1, specify a 0 for the array size, and sort the array from 1 instead of 0.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
sneaky smith12
20
Years of Service
User Offline
Joined: 30th Apr 2006
Location: Like id tell you, oh wait i just did
Posted: 19th Oct 2010 21:45 Edited at: 19th Oct 2010 22:44
Quote: "Read the file into an array while converting the strings to integers, sort it, then count the consecutive numbers."


After reading this comment I felt like a dork. Makes perfect sense. Thanks!

Edit:
So... I've tried that, and I don't see a problem with my code, but it stops in a crashes with the error: Runtime Error 118 - Array does not exist or array subscript out of bounds at 1129.

Anyone see something?


(fixed indentions)

If at first you dont succeed, LOWER YOUR STANDARDS.
Gael
15
Years of Service
User Offline
Joined: 27th Sep 2010
Location: Athens .
Posted: 19th Oct 2010 21:51
Hello sneaky smith12
Firstly you should pass the {AmountOfPoints} into the function.
It seems that the current function will pass the file into
an array of string lines.Meaning each part of the array is a line from the file.
You would need to rescan that array in order to find how many times a number occurs.
If you are looking for numbers as characters it will be easy to just compare each part of the string lines with the numbers as_strings , and count the times they occur.
If you are data extracting from that file , and you need ANY number indication that occurs , to be stored and counted (ex. 342-->2 times 5-->6 times etc) you might need (if hardcoding it yourself) to scan the string lines piece by piece , and check if each numerical character is followed by a.another numerical character or b.anything else.
on the event of a , you grow the number string (ex. previous "4" following "5" = "4"+"5" ="45"
on the event of b , you pass the number string into the log (ex. previous "4" next "p" = "4"


Login to post a reply

Server time is: 2026-07-22 03:51:08
Your offset time is: 2026-07-22 03:51:08