Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

Fudgie Braun

+ Follow
since Jun 08, 2020
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Fudgie Braun

fred rosenberger wrote:Parsing simply means reading in the data, and figuring out what parts are what.  Any modern language will have built-in tools to help you do this.  

One way you could try would be to read in the file a line at a time and save it to a string.  Then you can use various String methods to break apart that string into the pieces. In your case, you're going to break it apart by the dashes (and discarding them).  You'd be left with an array of six elements.

You could convert each to an integer type, or just continue using them as strings.

So you're saying I need to put the input text file into an array?
But before I put that into an array, I need to change each line into a string then put all those into the array?
2 months ago

Piet Souris wrote:And welcome to the Ranch. Enjoy the stay!

Oh, I forgot - thanks for welcoming me here in this forum...
2 months ago

Piet Souris wrote:My idea is to build a Map<Integer, List<LineNumbers>> from the input. To determine how many times two integers appear as pair, you simply take the intersection of the two corresponding lists. Don't know about C++, but in java there's a handy method for that.

By the way, can a Java pseudo-code about the solution better help in making a C++ source code version?
2 months ago

fred rosenberger wrote:You don't necessarily need to convert them into integers...After all you may someday want to parse a file with input like:


etc.  in other words, the fact that they look like integers now may not matter.  What you are really looking for is repeated 2-character patterns.  If you know they will always an only ever be 2-digit integers, then you can maybe take a few shortcuts.  You'd know they can only be 0-99.  That suggests you might be able to use an array with 100 elements to hold your count of each value found.

Now....Why 49?  is it because it's the first element in the first row, or is there some other criteria?  I don't think it's because it appears the most often, because I see 40 in there three times.

Oh, as for the "49", I'm only showing how the output would look like after looking through the entire list for the occurrence of that number (and other numbers I'm interested in).

By the way, you mentioned "parse a file"?
2 months ago

John Matthews wrote:Hi Fudgie - you've posted in the C/C++ forum, so presumably you are going to be writing your code in one of those; can you confirm which one? The intersection of corresponding lists approach will require a bit more effort in C

I will be coding in C++.
By the way, is pseudo-code the same as algorithm?
2 months ago
Supposed I have a text file having the results of the 6/49 lottery in it:

The following output must be written to a text file with filename, "occurrences.txt"?
49 - 2 times
49 appears with 13 and 42 - 2 times

I think to approach this problem, the following has to be done:
1) Convert the input text file into a machine-readable format
2) Split the items inside the file into separate fields
3) Convert all the numbers in the text file into integers (since the numbers in the text file are obviously strings, am I right?)
4) Count the occurrences of each individual number in the text file
5) Count the number of times each number appears in a trio of oft-occurring numbers
6) Transfer those recorded occurrences to an output text file

Any idea on the algorithm to go about this?
Just the algorithm - I'm not asking for any source code...
2 months ago