Added the Baker and Bird variant. Reset code.h to the default text size
[2dmatching.git] / bird.c
blob27d2caf997717d67c9612621af70722de22a6467
1 #include "code.h"
3 void bird()
4 {
5 int steps = 0;
7 /* x and y can be -1 */
8 int x, y;
10 unsigned int i, row, matches = 0;
12 /* Iterate rows */
13 for ( row = 0; row < n - m + 1; row++ ) {
15 x = 0;
17 /* Iterate through results on the same row */
18 while ( x != -1 ) {
20 x = aho( row, x, 0, n - m );
22 steps++;
24 // printf("x row %i column %i\n",row, x);
26 /* If a row is found, check the m - 1 rows underneath it for matches */
27 if ( x != -1 ) {
29 for ( i = 1; i < m; i++) {
30 /* Optimization: instead of checking against n chars on
31 subsequent rows, just check against the next m chars after x */
32 y = aho( row + i, x, i, x + m );
34 steps++;
36 // printf("y row %i column %i\n",row + i, y);
38 if ( y != x )
39 break;
41 /* If we reached to the final line above x without breaking, we have a match */
42 else if ( i == m -1)
43 matches++;
45 /* After each attempt,increase the counter + 1 */
46 x++;
50 printf("Bird: %i\n",matches);