Added the Baker and Bird variant. Reset code.h to the default text size
[2dmatching.git] / naive.c
blob84fc3e39a80bf421cb1cae15e4ee7cb4973ae85f
1 #include "code.h"
3 void naive()
5 int steps = 0;
6 unsigned int i, j, k, l;
7 unsigned int matches = 0;
8 unsigned int x, y;
10 /* Text size 7, pattern size 3, so the last element would be 7 - 3 + 1 = 5 */
11 for (y = 0; y < n - m + 1; y++) {
13 for (x = 0; x < n - m + 1; x++) {
15 k = y; /* reset text's vertical k (not to 0 but to the number of vertical loops) */
17 for (l = 0; l < m; l++) {
19 i = x; /* reset text's horizontal i (not to 0 but to the number of horizontal loops) */
21 for (j = 0; j < m; j++) {
23 steps++;
25 if ( pattern[l][j] != text[k][i] )
26 goto newline;
28 i++; /*increase horizontal drift*/
31 k++; /*increase vertical drift*/
34 /* If we reached here we should have a match */
35 matches++;
37 newline: ;
40 printf("Naive: %i\n",matches);