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

Fudgie Braun

Greenhorn
+ Follow
since Jun 08, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
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:

AB-24-Z7-1L-62-0O

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
Cheers
John



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:
49-05-13-42-18-45
43-24-36-16-39-22
32-48-05-18-34-29
13-14-07-41-48-39
47-05-17-13-37-49
06-23-34-21-46-37
06-42-13-40-11-37
39-44-40-21-32-20
17-26-38-43-01-02
49-13-42-36-40-10

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