Commits

Stephen Tanner committed 1f788cb

Fixed all cases. Changed array to print in same order as bitwise and recursive.

  • Participants
  • Parent commits 748f949

Comments (0)

Files changed (7)

File Debug/src/array.o

Binary file modified.

File Debug/src/bitwise.o

Binary file modified.

File Debug/src/recursive.o

Binary file modified.

File Debug/subc

Binary file modified.
 
     //Calculate how many shifts are left
     int moves = firstbit - length;
-    if (!moves) {
-        moves = 1;
+
+    if (moves < 0) {
+        return false;
     }
 
+
     //For each shift...
-    for (i = 0; i < moves; i ++) {
+    for (i = 0; i <= moves; i ++) {
         int j;
         //Populate the comp_array for comparing;
         for (j = 0; j < length; j++) {
     }
     //Since we found at least one, print the results
     printf("Array: Match Found\n\n");
-    printf("Array: number of matches: %d\n\n",match_cnt);
     printf("Array: starting bit positions: ");
     for (i = 0; i < SIZE; i++) {
         if (!matches[i]) {
             printf(",");
         }
     }
-    printf("\n\n\n");
+    printf("\n\n");
+    printf("Array: number of matches: %d\n\n\n",match_cnt);
     return true;
 }
 

File src/bitwise.c

     }
     //printf("%d", mask);
     int shift = firstbit - length;
+    if (shift < 0) {
+        return false;
+    }
     for (i  = 0; i <= shift; i++) {
 
         int masked = first_int & mask;

File src/recursive.c

         }
 
         int shifts_left = firstbit - length;
-        if (!shifts_left) {
-            shifts_left = 1;
+        if (shifts_left < 0 ) {
+            return false;
         }
+
         bool sub_found = find_subs(found, &match_count, shifts_left, first_int, second_int, mask, firstbit);
 
         if (sub_found) {
             printf("\n\n");
-            printf("Recursive: number of matches: %d\n\n\n",match_count);
+            printf("Recursive: number of matches: %d\n",match_count);
             return true;
         }
         else {
 bool find_subs(bool found, int *match_count, int shifts_left, int first_int, int second_int, int mask, int firstbit) {
 
     //Handle the base case
-    if (shifts_left == 0) {
+    if (shifts_left < 0) {
         if (*match_count == 0) {
             return false;
         }
     int masked = (first_int & mask);
     if (masked == second_int) {
         //matches[*match_count] = SIZE - shifts_left;
-        int bit = firstbit -shifts_left;
+        int bit = firstbit - shifts_left;
         if (!bit) {
             bit = 1;
         }