- #1
Absolutism
- 28
- 0
Homework Statement
So basically I got this problem and I am still constructing an algorithm for it. I am not entirely sure the algorithm is going in the right direction, though. The problem is as follows:
The 2-D array and the pattern are read from two input files named Array and Pattern. Each
line of these files contains a row; the numbers on each line are separated by spaces.
Organize hierarchically your code, writing a function that counts the pattern appearances for
just one fixed orientation, and calling this function from the main function for each of the 4
orientations. (The number of levels of hierarchy is arbitrary large, that is, the function may call other functions as well.)
For simplicity, there is no need to consider only distinct patterns: for instance, if the pattern is
a 2 × 2 array having all the elements equal to 1, its appearance in the larger array may be reported
4 times, once for each orientation.
Homework Equations
The Attempt at a Solution
My problem is with constructing the algorithm initially. What I thought of, is to initialize line by line to a string from the pattern, and compare it to the elements in the array from i=0 until i=n-1 (if n is the number of elements in the row of the pattern) and if all the elements are equal, we move to the next column until we reach the column in the array that is equal to the same number of the final column of the pattern. If so, we can start looking for the pattern by incrementing n-1 columns and m-1 rows for example (these being the number of elements in the rows and columns) and if not, we increment by one. I am not sure if I am moving in the right direction though? I have just studied file processing, so I do not think I can check rows and columns at the same time like in a 2D matrix.