diff --git a/Algoritmic Schemes/Backtracking/Eight Queens/allSolutions.txt b/Algoritmic Schemes/Backtracking/Eight Queens/allSolutions.txt new file mode 100644 index 0000000..8f42f1a --- /dev/null +++ b/Algoritmic Schemes/Backtracking/Eight Queens/allSolutions.txt @@ -0,0 +1,1748 @@ +SOLUTION 1 +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 2 +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 3 +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 4 +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 5 +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 6 +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 7 +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 8 +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 9 +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 10 +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 11 +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 12 +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 13 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 14 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 15 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 16 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 17 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 18 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 19 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 20 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 21 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 22 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 23 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 24 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 25 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 26 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 27 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 28 +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 29 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 30 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 31 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- + +SOLUTION 32 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 33 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 34 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 35 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 36 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- + +SOLUTION 37 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- + +SOLUTION 38 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 39 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 40 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 41 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 42 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- + +SOLUTION 43 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 44 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 45 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 46 +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 47 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 48 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 49 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 50 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- + +SOLUTION 51 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 52 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 53 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 54 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- + +SOLUTION 55 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 56 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 57 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 58 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 59 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 60 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- + +SOLUTION 61 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 62 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 63 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- + +SOLUTION 64 +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 65 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 66 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 67 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 68 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 69 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 70 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- + +SOLUTION 71 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- + +SOLUTION 72 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- + +SOLUTION 73 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 74 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 75 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 76 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 77 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 78 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- + +SOLUTION 79 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 80 +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 81 +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 82 +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 83 +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 84 +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 85 +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 86 +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 87 +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + +SOLUTION 88 +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 89 +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 90 +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- + +SOLUTION 91 +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- + +SOLUTION 92 +--------------------------------- +| _ | _ | _ | _ | _ | _ | _ | X | +--------------------------------- +| _ | _ | _ | X | _ | _ | _ | _ | +--------------------------------- +| X | _ | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | X | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | X | _ | _ | +--------------------------------- +| _ | X | _ | _ | _ | _ | _ | _ | +--------------------------------- +| _ | _ | _ | _ | _ | _ | X | _ | +--------------------------------- +| _ | _ | _ | _ | X | _ | _ | _ | +--------------------------------- + diff --git a/Algoritmic Schemes/Backtracking/Eight Queens/eightQueens.c b/Algoritmic Schemes/Backtracking/Eight Queens/eightQueens.c new file mode 100644 index 0000000..d07c933 --- /dev/null +++ b/Algoritmic Schemes/Backtracking/Eight Queens/eightQueens.c @@ -0,0 +1,150 @@ +#include +#include + +#include "eightQueens.h" + +//Counter to store solution number +int solNumber = 1; + +/* Gives 1 solution. + * Backtraking algorithm that solves the N-queens problem. It uses a counter "currentQueen" that marks which queen + * is searching for a box to stay. To know in which boxes a queen can or cannot be it uses 3 arrays that store + * what boxes in each row, diagonal or transversal diagonal are o are not busy. + * + * The algorithm "ignores" colums because boxes are searched according to the next clear column. This is, each column + * can only have 1 queen, so when a queen is stored in a box, the algorithm works recursively with the rest of + * the board ignoring the busy columns used before. + * + * The algorithm finishes when all queens are placed (there is a solution) or when all posible combinations are tried. + * In case there is a solution, it will be returned as and array with the positions in the rows where the queens + * where places: for example, if solution[1] = 4 means that theres a queen in the box [1(row)][4(column)] in the board + */ +void queensAlg(int currentQueen,int *success,int *solution, int *rows,int *d, int *t, int numQueens){ + int j=-1; + *success = 0; + do{ + j++; + if(rows[j] && d[currentQueen-j+(numQueens-1)] && t[currentQueen+j]){ + //If there is no queen in the box (row/diagonal/transversal diagonal), + // it registers it in that box + solution[currentQueen] = j; + rows[j] = d[currentQueen-j+(numQueens-1)] = t[currentQueen+j] = 0; + + if(currentQueen == (numQueens-1)){ + //If the queen registered was the last queen, it means that all + // queens where correctly placed and it finishes + *success = 1; + + }else{ + //If the queen registered wasnt the last queen, it means that there + // are more queens that remain unplaced, so it continues + queensAlg(currentQueen+1, success, solution, rows, d, t, numQueens); + + //If there is no success placing the queen in that box, it goes back,leaves + // free the box (row/diagonal/transversal diagonal) and continues with the next + // box + if(!(*success)){ + rows[j] = d[currentQueen-j+(numQueens-1)] = t[currentQueen+j] = 1; + } + } + } + + //If there is no success or there are no more boxes remaining (j == (numQueens-1)), it finishes + }while(!(*success) && j!=(numQueens-1)); +} + + +/* Gives all posible solutions + * Backtraking algorithm, same as before, but gives all posible solutions to N-queens problem. + */ +void queensAlgAllSolutions(int currentQueen,int *solution, int *rows,int *d, int *t, int numQueens, FILE *niceFile){ + int j; + for(j=0; jnum = solNumber; + sol->numQueens = numQueens; + + sol->sol = malloc(numQueens * sizeof(char *)); + if(sol->sol == NULL) + return NULL; + + for(i=0; isol)[i] = malloc(numQueens * sizeof(char)); + if((sol->sol)[i] == NULL) + return NULL; + } + + for(i=0; isol[i][j]='_'; + } + sol->sol[i][solution[i]]='X'; + } + + return sol; +} + +/* + * Saves a solution in a file. The file can be an external file or the standar output + * file to print via terminal the solution. + */ +void saveSolution(Solution *solution, FILE *niceFile){ + if(solution == NULL) return; + + if(niceFile != NULL){ + int i,j,k; + + fprintf(niceFile,"SOLUTION %d\n",solution->num); + + for(k=0; k<(solution->numQueens*4+1); k++){ + fprintf(niceFile,"-"); + } + fprintf(niceFile,"\n"); + for(i=0; inumQueens; i++){ + fprintf(niceFile,"| "); + + for(j=0; jnumQueens; j++){ + fprintf(niceFile,"%c | ",solution->sol[i][j]); + } + + fprintf(niceFile,"\n"); + + for(k=0; k<(solution->numQueens*4+1); k++){ + fprintf(niceFile,"-"); + } + + fprintf(niceFile,"\n"); + } + fprintf(niceFile, "\n"); + + } +} + + + diff --git a/Algoritmic Schemes/Backtracking/Eight Queens/eightQueens.h b/Algoritmic Schemes/Backtracking/Eight Queens/eightQueens.h new file mode 100644 index 0000000..fee2cc0 --- /dev/null +++ b/Algoritmic Schemes/Backtracking/Eight Queens/eightQueens.h @@ -0,0 +1,25 @@ +#ifndef __EIGHT_QUEENS_H__ +#define __EIGHT_QUEENS_H__ + +#include + +// Number of queens +#define QUEENS 8 + +//Struct to store solutions +typedef struct solution{ + int num; //To store the solution number + int numQueens; //Number of queens of the solution + char **sol; //Bidimension array to store the board with the solution +}Solution; + + +int solNumber; + +void queensAlg(int currentQueen,int *success,int *x, int *rows,int *d, int *t, int numQueens); +void queensAlgAllSolutions(int currentQueen,int *solution, int *rows,int *d, int *t, int numQueens, FILE *niceFile); + +Solution* createBoardSolution(int *solution, int numQueens); +void saveSolution(Solution *solution, FILE *niceFile); + +#endif diff --git a/Algoritmic Schemes/Backtracking/Eight Queens/main.c b/Algoritmic Schemes/Backtracking/Eight Queens/main.c new file mode 100644 index 0000000..b9a0af5 --- /dev/null +++ b/Algoritmic Schemes/Backtracking/Eight Queens/main.c @@ -0,0 +1,70 @@ +#include +#include + +#include "eightQueens.h" + +int main(int argc, char **argv){ + + int currentQueen=0; //Queen that is searching box to stay + int success; //For 1 solution, indicates if there is a solution or not for the problem + int solution[QUEENS]; //Stores the box where each queen is per row (ej: if solution[0]=4, means + // that the queen is on row 4, column 0 + + int rows[QUEENS]; //Stores the rows that have/not have a queen + int diag[QUEENS*2 -1]; //Stores the diagonals that have/not have a queen + int transDiag[QUEENS*2 -1]; //Stores the transversal diagonals that have/not have a queen + + int i,j,k; + + + // ONE SOLUTION + for(i=0; i +#include + +#include "knightTravel.h" + +/* Backtraking algorithm to solve the knight travel problem. This problem consists on travelling + * all the chess boxes using a knight. + * + * This algorithm uses 2 arrays representing the possible movements for the knight (movX and movY). + * There are 8 possible movements for the knight, ignoring the ones that cause the knight to go out + * of the board. + * The algorithm gets and initial position and calculates the next possible box using this movements, + * checking if the new position is inside the board and the box is free or not. If the box is free, + * it registers the movement in the board and searches recursively using this new position as the + * "initial position" for the next movement. + * + * The algorithm will end when the knight has visited the entire board (there is a solution) or when it + * can no longer move because there are no more possible movements. + */ +void knightTravel(int num, int *success, int x, int y, int **board, int dim ,int *movX, int *movY){ + *success = 0; + int j = -1; + int xn, yn; + + do{ + j++; + //Moves from x,y calculating the next possible box (xn,yn) + xn = x + movX[j]; + yn = y + movY[j]; + + if((xn=0) && (yn=0) && (board[xn][yn]==0)){ + board[xn][yn] = num; + + if(num < dim*dim){ + knightTravel(num+1, success, xn, yn, board, dim, movX, movY); + + if(!(*success)){ + board[xn][yn] = 0; + } + + }else{ + (*success) = 1; + } + } + }while(!(*success) && (j<8)); +} + + + +/* + * Creates a new board and initializes it. + */ +int **createAndInitBoard(int dim){ + int i,j; + + //Create board + int **board; + board = malloc(dim * sizeof(int *)); + for(i=0; i +#include + +#include "knightTravel.h" + +#define DIM 8 + +int main(int argc, char **argv){ + //Posibble movements for the horse + int movX[8]={-2,-2,-1,-1, 1, 1, 2,2}; //Mov in x + int movY[8]={-1, 1,-2, 2,-2, 2,-1,1}; //Mov in y + + int success=0; //Indicates if there is solution or not + int dim; //Dimension of the board + int **board; //Board for the algorithm + + + //Create board + do{ + printf("Dimension of the board (>0)?:"); + scanf("%d%*c",&dim); + }while(dim <= 0); + + board = createAndInitBoard(dim); + + + //Set initial position + int x0; //pos x initial + int y0; //pos y initial + + printf("Set start position\n"); + do{ + printf(" row? (0-%d):",dim-1); + scanf("%d%*c",&x0); + }while(x0 < 0 || x0>=dim); + + do{ + printf(" column? (0-%d):",dim-1); + scanf("%d%*c",&y0); + }while(y0 < 0 || y0>=dim); + + + //Algorithm + printf("\n\033[0;31m Initial position -> (%d,%d) \033[0m",x0,y0); + board[x0][y0]=1; //Set initial position in the board + knightTravel(2, &success, x0, y0, board, dim, movX, movY); + + if(success) + printBoard(board,dim); + else + printf("\nThere is no solution\n"); + + puts(""); + return 0; +} + + + + diff --git a/Algoritmic Schemes/Backtracking/Knight Travel/makefile b/Algoritmic Schemes/Backtracking/Knight Travel/makefile new file mode 100644 index 0000000..99f4742 --- /dev/null +++ b/Algoritmic Schemes/Backtracking/Knight Travel/makefile @@ -0,0 +1,21 @@ +CC=gcc +#CFLAGS=-c +CFLAGS=-c -g +EXECUTABLE_NAME=knightTravel + +all: $(EXECUTABLE_NAME) + +$(EXECUTABLE_NAME): main.o knightTravel.o + $(CC) $^ -o $@ -lm + +main.o: main.c + $(CC) $(CFLAGS) main.c + +knightTravel.o: knightTravel.c knightTravel.h + $(CC) $(CFLAGS) knightTravel.c + + +clean: + rm *.o + rm $(EXECUTABLE_NAME) + diff --git a/Algoritmic Schemes/Backtracking/Maze Solver/main.c b/Algoritmic Schemes/Backtracking/Maze Solver/main.c new file mode 100644 index 0000000..b24f64e --- /dev/null +++ b/Algoritmic Schemes/Backtracking/Maze Solver/main.c @@ -0,0 +1,40 @@ +#include +#include + +#include "mazeSolver.h" + + +int main(int argc, char **argv){ + + FILE *f = fopen("maze.txt","r"); + + if(f == NULL) return -1; + + Maze *maze = loadMaze(f); + fclose(f); + + //Possible movements from a box to another + int movX[4]={1,-1,0,0}; //Mov in X + int movY[4]={0,0,1,-1}; //Mov in Y + + maze->movX = movX; + maze->movY = movY; + + maze->maze[maze->xStart][maze->yStart] = '*'; + int success; + mazeSolver(maze, &success, maze->xStart, maze->yStart); + + if(!success){ + printf("There is not a suitable path"); + + }else{ + printMaze(maze); + } + + puts(""); + return 0; +} + + + + diff --git a/Algoritmic Schemes/Backtracking/Maze Solver/makefile b/Algoritmic Schemes/Backtracking/Maze Solver/makefile new file mode 100644 index 0000000..17fe8d1 --- /dev/null +++ b/Algoritmic Schemes/Backtracking/Maze Solver/makefile @@ -0,0 +1,21 @@ +CC=gcc +#CFLAGS=-c +CFLAGS=-c -g +EXECUTABLE_NAME=mazeSolver + +all: $(EXECUTABLE_NAME) + +$(EXECUTABLE_NAME): main.o mazeSolver.o + $(CC) $^ -o $@ -lm + +main.o: main.c + $(CC) $(CFLAGS) main.c + +mazeSolver.o: mazeSolver.c mazeSolver.h + $(CC) $(CFLAGS) mazeSolver.c + + +clean: + rm *.o + rm $(EXECUTABLE_NAME) + diff --git a/Algoritmic Schemes/Backtracking/Maze Solver/maze.txt b/Algoritmic Schemes/Backtracking/Maze Solver/maze.txt new file mode 100644 index 0000000..6a5b414 --- /dev/null +++ b/Algoritmic Schemes/Backtracking/Maze Solver/maze.txt @@ -0,0 +1,11 @@ +##S######################################### +## ########### ######## +## #################### #### +## ########### ####### ########### +## ######## ####### ######### ### ## +#### ######### ####### ######### ### #### ## + # ######### ######### ### ## ## + ### ########################### ##### ## ## + ###### ### ############ ## ## + ####### ################### # +##########################################E# diff --git a/Algoritmic Schemes/Backtracking/Maze Solver/mazeSolver.c b/Algoritmic Schemes/Backtracking/Maze Solver/mazeSolver.c new file mode 100644 index 0000000..f6cd270 --- /dev/null +++ b/Algoritmic Schemes/Backtracking/Maze Solver/mazeSolver.c @@ -0,0 +1,132 @@ +#include +#include + +#include "mazeSolver.h" + +/* Backtracking algorithm to search for a valid path to solve a maze. + * Just like the Knight Travel algorithm, it uses a board to store the + * maze and 2 arrays with the possible movements the "head" that + * is searching for the path can move. + * This movements just repeat until the algorithm finds the end or there + * are no more possible movements. + * In the first case,the algorithm finds a suitable path and returns + * a success, so the maze and the path are printed. + * In the second case, the algorithm tries all possibilities but it can + * not find a path, so it returns no success and finishes. + */ +void mazeSolver(Maze *maze, int *success, int x, int y){ + *success = 0; + int j=-1; + int xn, yn; + + do{ + j++; + xn = maze->movX[j] + x; + yn = maze->movY[j] + y; + + if((xn>=0 && xnheight) && (yn>=0 && ynwidth) && (maze->maze[xn][yn]==' ' || maze->maze[xn][yn]=='E')){ + maze->maze[xn][yn]='*'; + + if(xn==maze->xEnd && yn==maze->yEnd){ + *success = 1; + + }else{ + mazeSolver(maze, success, xn, yn); + + if(!(*success)){ + maze->maze[xn][yn] =' '; + } + } + } + }while((!(*success) && (j<4))); +} + +/* Prints the maze showing the start, the end and the path + */ +void printMaze(Maze *maze){ + int i,j; + printf("\033[1;35mStart -> \033[1;32m*\033[0m\n"); + printf("\033[1;35mEnd -> \033[1;31m*\033[0m\n"); + printf("\033[1;35mPath -> \033[0;36m*\033[0m\n\n"); + + for(i=0; iheight; i++){ + for(j=0; jwidth; j++){ + if(i == maze->xStart && j == maze->yStart){ + printf("\033[1;32m%c\033[0m",maze->maze[i][j]); + + }else if(i == maze->xEnd && j == maze->yEnd){ + printf("\033[1;31m%c\033[0m",maze->maze[i][j]); + + }else if(maze->maze[i][j] == '*'){ + printf("\033[0;36m%c\033[0m",maze->maze[i][j]); + + }else{ + printf("%c",maze->maze[i][j]); + } + } + puts(""); + } +} + + +/* Loads a maze from a txt file. + * The maze has to be created using '#' character and the start + * and end have to be marked as 'S' for start and 'E' for end. + */ +Maze *loadMaze(FILE *f){ + Maze *maze = malloc(sizeof(Maze)); + + char * line = NULL; + size_t len = 0; + int i,j, mazeWidth, mazeHeight; + + //Gets the width, height, start and end of the maze + mazeWidth = mazeHeight = 0; + while (getline(&line, &len, f) != -1) { + i=0; + while(line[i] != '\n'){ + if(line[i] == 'S'){ + maze->xStart = mazeHeight; + maze->yStart = i; + } + + if(line[i] == 'E'){ + maze->xEnd = mazeHeight; + maze->yEnd = i; + } + + i++; + } + + if(i > mazeWidth) mazeWidth = i; + + + mazeHeight++; + } + + //Creates the maze with the data + maze->width = mazeWidth; + maze->height = mazeHeight; + + maze->maze = malloc(maze->height * sizeof(char *)); + for(i=0; iheight; i++){ + maze->maze[i] = malloc(maze->width * sizeof(char)); + } + + + //Loads maze into the array + fseek(f,0,SEEK_SET); + for(i=0; iheight; i++){ + getline(&line, &len, f); + for(j=0; jwidth; j++){ + if(jmaze[i][j] = line[j]; + }else{ + maze->maze[i][j] = ' '; + } + } + } + + return maze; +} + diff --git a/Algoritmic Schemes/Backtracking/Maze Solver/mazeSolver.h b/Algoritmic Schemes/Backtracking/Maze Solver/mazeSolver.h new file mode 100644 index 0000000..9f032d6 --- /dev/null +++ b/Algoritmic Schemes/Backtracking/Maze Solver/mazeSolver.h @@ -0,0 +1,20 @@ +#ifndef __MAZE_SOLVER_H__ +#define __MAZE_SOLVER_H__ + +#include + +//Struct with info of the maze +typedef struct maze{ + char **maze; + int width,height; + int xStart, yStart; + int xEnd, yEnd; + int *movX, *movY; +}Maze; + + +void mazeSolver(Maze *maze, int *success, int x, int y); +void printMaze(Maze *maze); +Maze *loadMaze(FILE *f); + +#endif diff --git a/Algoritmic Schemes/Divide and Conquer/Hanoi/hanoi.c b/Algoritmic Schemes/Divide and Conquer/Hanoi/hanoi.c new file mode 100644 index 0000000..cb5bb35 --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/Hanoi/hanoi.c @@ -0,0 +1,75 @@ +#include "hanoi.h" + +/* Hanoi Towers problem solved with recursion (dyc algorithm) + * O(2^n) + * Minimun number of movements to solve it: 2^(number of disks) - 1 + */ + +//Simple gui hanoi version +void simpleHanoi(int disks, int origen, int destination, int aux){ + if(disks > 0){ + simpleHanoi(disks-1, origen, aux, destination); + + printf("\nMoves disk %d from tower %c to tower %c",disks,origen,destination); + printf("\n(%d,%d,%d,%d)\n",disks,origen,destination,aux); + + simpleHanoi(disks-1, aux, destination, origen); + } +} + +//Better gui hanoi version +void hanoi(char **towers, int disks, int currentDisks, int origen, int destination, int aux){ + if(currentDisks > 0){ + hanoi(towers,disks, currentDisks-1, origen, aux, destination); + + moveTowers(towers, disks, origen, destination); + showTowers(towers, disks); + + hanoi(towers,disks, currentDisks-1, aux, destination, origen); + } +} + + + +/* Funtions to display hanoi + * in a graphical way. + */ +void initTowers(char **towers, int disks){ + int i,j; + + for(i=0, j=disks; i=0; i--){ + printf(" | %c | | %c | | %c |\n",towers[0][i],towers[1][i],towers[2][i]); + } + printf(" +---+ +---+ +---+\n\n"); +} + +void moveTowers(char **towers, int disks, int o, int d){ + int i; + char diskValue; + + //Origin + i=disks-1; + while(towers[o-1][i] == (char) 32) + i--; + diskValue = towers[o-1][i]; + towers[o-1][i] = (char) 32; + + //Destination + i=0; + while(towers[d-1][i] != (char)32) + i++; + + towers[d-1][i] = diskValue; +} diff --git a/Algoritmic Schemes/Divide and Conquer/Hanoi/hanoi.h b/Algoritmic Schemes/Divide and Conquer/Hanoi/hanoi.h new file mode 100644 index 0000000..0bd06af --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/Hanoi/hanoi.h @@ -0,0 +1,17 @@ +#ifndef __HANOI_H__ +#define __HANOI_H__ + +#include +#include + +#define DRAW_TOWERS + +void simpleHanoi(int disks, int origen, int destination, int aux); +void hanoi(char **towers, int disks, int currentDisks, int origen, int destination, int aux); + + +void initTowers(char **towers, int disks); +void showTowers(char **towers, int disks); +void moveTowers(char **towers, int disks, int o, int d); + +#endif diff --git a/Algoritmic Schemes/Divide and Conquer/Hanoi/main.c b/Algoritmic Schemes/Divide and Conquer/Hanoi/main.c new file mode 100644 index 0000000..d1249b4 --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/Hanoi/main.c @@ -0,0 +1,52 @@ +#include +#include + +#include "hanoi.h" + + +int main(int argc, char **argv){ + + int disks, i, j; + + #ifdef DRAW_TOWERS + char *towers[3]; + + for(i=0; i<3; i++){ + if(NULL == (towers[i] = malloc(disks * sizeof(char)))){ + for(j=i-1; j>=0; j--){ + free(towers[i]); + } + return -1; + } + } + #endif + + + do{ + printf("\nNumber of disks?(min 1):"); + scanf("%d%*c",&disks); + if(disks <=0) + printf("\n\tInvalid number of disks"); + + }while(disks <= 0); + + + + #ifdef DRAW_TOWERS + initTowers(towers, disks); + showTowers(towers, disks); + hanoi(towers,disks, disks,1,3,2); + #else + printf("\n(%d,%d,%d,%d)\n",disks,1,2,3); + simpleHanoi(disks,1,3,2); + #endif + + + printf("\n\nMinimun number of movements: %ld\n\n",(long)(pow(2,disks) - 1)); + + return 0; +} + + + + diff --git a/Algoritmic Schemes/Divide and Conquer/Hanoi/makefile b/Algoritmic Schemes/Divide and Conquer/Hanoi/makefile new file mode 100644 index 0000000..37071ce --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/Hanoi/makefile @@ -0,0 +1,20 @@ +CC=gcc +#CFLAGS=-c +CFLAGS=-c -g +EXECUTABLE_NAME=hanoi + +all: $(EXECUTABLE_NAME) + +$(EXECUTABLE_NAME): main.o hanoi.o + $(CC) $^ -o $@ -lm + +main.o: main.c + $(CC) $(CFLAGS) main.c + +hanoi.o: hanoi.c hanoi.h + $(CC) $(CFLAGS) hanoi.c + + +clean: + rm *.o + rm $(EXECUTABLE_NAME) diff --git a/Algoritmic Schemes/Divide and Conquer/Other Algorithms/arraysListsUtilities.c b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/arraysListsUtilities.c new file mode 100644 index 0000000..3f21da7 --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/arraysListsUtilities.c @@ -0,0 +1,116 @@ +#include "arraysListsUtilities.h" + +int *createArray(int size){ + if(size <=0) + return NULL; + + + int *array; + if(NULL == (array=malloc(size * sizeof(int)))){ + #ifdef DEBUG + fprintf(stderr,"Error: Can not reserve memory for array\n"); + #endif + return NULL; + } + + srand(time(NULL)); + for(int i=0; iinfo = info; + new->next = NULL; + return new; +} + + +void createList(Node **list, int numNodes){ + if(*list==NULL){ + int i; + Node *new=NULL, *last=NULL; + + srand(time(NULL)); + for(i=0; inext = new; + last=new; + } + new=NULL; + } + } +} + +void printList(Node *list){ + Node *aux=list; + while(aux!=NULL){ + printf("%d ", aux->info); + aux = aux->next; + } +} + + + + + + + + + + + + + + + diff --git a/Algoritmic Schemes/Divide and Conquer/Other Algorithms/arraysListsUtilities.h b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/arraysListsUtilities.h new file mode 100644 index 0000000..1e23655 --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/arraysListsUtilities.h @@ -0,0 +1,25 @@ +#ifndef __ARRAYS_UTILITY__ +#define __ARRAYS_UTILITY__ + +#include +#include +#include + +//Arrays utilities +int *createArray(int size); +int *createSortedArray(int size); +void printArray(int *array, int arraySize); + +void swap(int *array, int i, int j); + +//Lists utilities +typedef struct node{ + int info; + struct node *next; +}Node; + +Node* createNode(int info); +void createList(Node **list, int numNodes); +void printList(Node *list); + +#endif diff --git a/Algoritmic Schemes/Divide and Conquer/Other Algorithms/dcAlgorithms.c b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/dcAlgorithms.c new file mode 100644 index 0000000..50c1bdf --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/dcAlgorithms.c @@ -0,0 +1,83 @@ +#include "dcAlgorithms.h" + +/* Divide & Conquer algorith very similar to binary search, but + * in this case it divides the array in 3 parts instead of + * 2 parts. + * O(lg₃(n)) + */ +int ternarySearch(int value, int *array, int firstElement, int lastElement){ + if(firstElement > lastElement){ + return -1; + }else{ + int i = firstElement; + int j = lastElement; + + //Array [0,1,2, 3,4,5, 6,7,8] + // [k] [l] + int k = i + (j - i) / 3; + int l = j - (j - i) / 3;; + + if(value < array[k]){ + //First part of the array (1/3 of the array) + j = k-1; + + }else if(value > array[k]){ + if(value < array[l]){ + //Second part of the array (2/3 of the array) + i = k+1; + j = l-1; + + }else if(value > array[l]){ + //Third part of the array (3/3 of the array) + i = l+1; + + }else{ + return l; + } + + }else{ + return k; + } + + return ternarySearch(value, array, i, j); + } +} + + + + +/* Returns the base powered up to exp + * O(lg(n)) + */ +int powerOf(int base, int exp){ + //printf("\nBase:%d\nExp:%d",base,exp); + if(exp == 1){ + return base; + + }else{ + int res = powerOf(base, exp/2) * powerOf(base, exp/2); + if(exp % 2 != 0){ + res *= base; + } + return res; + } +} + + + + + + + + + + + + + + + + + + + diff --git a/Algoritmic Schemes/Divide and Conquer/Other Algorithms/dcAlgorithms.h b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/dcAlgorithms.h new file mode 100644 index 0000000..d44eb94 --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/dcAlgorithms.h @@ -0,0 +1,10 @@ +#ifndef __DCALGORITHMS_H__ +#define __DCALGORITHMS_H__ + + +int ternarySearch(int value, int *array, int firstElement, int lastElement); +int powerOf(int base, int exp); + + + +#endif diff --git a/Algoritmic Schemes/Divide and Conquer/Other Algorithms/main.c b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/main.c new file mode 100644 index 0000000..5871dcc --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/main.c @@ -0,0 +1,66 @@ +#include +#include + +#include "arraysListsUtilities.h" +#include "dcAlgorithms.h" + +int callTernarySearch(void); + +int main(int argc, char **argv){ + + //Code for ternary search + //return callTernarySearch(); + + //Code for powerOf + /* + int num; + int exp; + + printf("Num?:"); + scanf("%d%*c",&num); + + printf("Exp?:"); + scanf("%d%*c",&exp); + + if(num <0 || exp<=0) return -1; + + int res = powerOf(num,exp); + printf("\n%d power to %d is %d\n",num, exp, res); + return 0; + */ + +} + + + +int callTernarySearch(void){ + int *array; + int arraySize; + int valueToFind; + + printf("Array size?:"); + scanf("%d%*c",&arraySize); + + array = createSortedArray(arraySize); + + if(array == NULL) return -1; + + printArray(array,arraySize); + printf("\n"); + + printf("\nValue?:"); + scanf("%d%*c",&valueToFind); + + int pos = ternarySearch(valueToFind,array,0,arraySize-1); + + if(pos == -1) + printf("\nCan not find value %d in the array\n",valueToFind); + else + printf("\nValue %d finded at pos %d\n",valueToFind, pos); + + return 0; + +} + + + diff --git a/Algoritmic Schemes/Divide and Conquer/Other Algorithms/makefile b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/makefile new file mode 100644 index 0000000..d824ff1 --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/Other Algorithms/makefile @@ -0,0 +1,22 @@ +CC=gcc +#CFLAGS=-c +CFLAGS=-c -g +EXECUTABLE_NAME=dc + +all: $(EXECUTABLE_NAME) + +$(EXECUTABLE_NAME): main.o dcAlgorithms.o arraysListsUtilities.o + $(CC) $^ -o $@ -lm + +main.o: main.c + $(CC) $(CFLAGS) main.c + +dcAlgorithms.o: dcAlgorithms.c dcAlgorithms.h + $(CC) $(CFLAGS) dcAlgorithms.c + +arraysListsUtilities.o: arraysListsUtilities.c arraysListsUtilities.h + $(CC) $(CFLAGS) arraysListsUtilities.c + +clean: + rm *.o + rm $(EXECUTABLE_NAME) diff --git a/Algoritmic Schemes/Divide and Conquer/README.md b/Algoritmic Schemes/Divide and Conquer/README.md new file mode 100644 index 0000000..ac06d2f --- /dev/null +++ b/Algoritmic Schemes/Divide and Conquer/README.md @@ -0,0 +1 @@ +# Divide and Conquer Algorithms diff --git a/Algoritmic Schemes/Voracious Algorithms/Backpack problem/backPack.c b/Algoritmic Schemes/Voracious Algorithms/Backpack problem/backPack.c new file mode 100644 index 0000000..7eb8395 --- /dev/null +++ b/Algoritmic Schemes/Voracious Algorithms/Backpack problem/backPack.c @@ -0,0 +1,54 @@ +#include +#include + +#include "backPack.h" + +/* Voracious algorithm to solve the backpack problem. + * The problem is to maximize the value of the backpack + * with a given weigth. + * This max value will depend on the selection function that in + * this case, depends on weight and value of the objects: depending + * on the order of the arrays that contain the weights/values, the + * result will be different. + * + * There are 2 possible algorithms: one with object division and one + * without. + * The one with object division allows to insert a fraction of the + * object in the backpack, this is, objects can be fractioned and add + * only a part of it. + * The other one without object division only allows to add a full object + * to the backpack. + * + * The differences remain on the solution: with object division will always + * give an optimal value but dont represent the reallity; the other one + * without object division represents reallity but will not always give + * an optimal value + */ +double *backPack(int capacity, int *weights, int *values, int n){ + double *solution = malloc(n * sizeof(double)); + + if(solution == NULL){ + return NULL; + } + memset(solution, 0, n-1); //Initialize solution to 0 + + + int currentWeight = 0; + int j = n-1; + + while( (j>=0) && (currentWeight +#include + +#include "backPack.h" + + +int main(int argc, char **argv){ + + //Depending on the order, result will be better/worse + // This order will be the selection funtion of the algorithm + int n = 5; + int values[5] = {55,75,95,76,55}; + int weights[5] = {50,40,45,35,25}; + + int backPackCapacity = 110; + double *myBackPack,backPackValue=0; //Solución + + myBackPack = backPack(backPackCapacity, weights, values, n); + + if(myBackPack == NULL){ + printf("\nThere is no solution\n"); + return -1; + } + + int i; + for (i=0; i Quantity \033[0;35m%.3lf\n\033[0m",weights[i],myBackPack[i]); + backPackValue += myBackPack[i] * values[i]; + } + printf ("\n\033[1;36mBackpack total value: %.2f\n\033[0m",backPackValue); + + puts(""); + return 0; +} + + + + diff --git a/Algoritmic Schemes/Voracious Algorithms/Backpack problem/makefile b/Algoritmic Schemes/Voracious Algorithms/Backpack problem/makefile new file mode 100644 index 0000000..6cafcb4 --- /dev/null +++ b/Algoritmic Schemes/Voracious Algorithms/Backpack problem/makefile @@ -0,0 +1,20 @@ +CC=gcc +#CFLAGS=-c +CFLAGS=-c -g +EXECUTABLE_NAME=backPack + +all: $(EXECUTABLE_NAME) + +$(EXECUTABLE_NAME): main.o backPack.o + $(CC) $^ -o $@ -lm + +main.o: main.c + $(CC) $(CFLAGS) main.c + +backPack.o: backPack.c backPack.h + $(CC) $(CFLAGS) backPack.c + + +clean: + rm *.o + rm $(EXECUTABLE_NAME) diff --git a/Algoritmic Schemes/Voracious Algorithms/Coin Change Machine/chm.c b/Algoritmic Schemes/Voracious Algorithms/Coin Change Machine/chm.c new file mode 100644 index 0000000..6c08c7f --- /dev/null +++ b/Algoritmic Schemes/Voracious Algorithms/Coin Change Machine/chm.c @@ -0,0 +1,63 @@ +#include +#include + +#include "chm.h" + +/* Gives a solution to the problem of changing coins in a machine + * using Voracious Algorithmic Scheme + * + * It gives a solution by substracting from the total amount using + * the coin with highest value that is equal or smaller than the + * total amount. This process is repeated until the total amount + * remains 0 so there is a solution, or until the total amount is + * still greater than 0 but there is no coin with a smaller value + * than the total amount, so in this case there is no solution + * to the problem + */ +int *coinsChange(int amount, int *coins,int numCoins){ + int total = amount; + int nC = numCoins-1; + + int *solution = malloc(numCoins * sizeof(int)); + if(solution == NULL) return NULL; + + memset(solution, 0, nC); //Initialize solution to 0 + + while(total > 0){ + while( nC>=0 && coins[nC]>total ) + nC--; + + if(nC < 0){ + return NULL; + }else{ + solution[nC] = total / coins[nC]; + total -= coins[nC]*solution[nC]; + } + } + return solution; +} + +// Another version of the coin change machine +int *coinsChangeV2(int amount, int *coins, int numCoins){ + int accumChange = 0; + int nC = numCoins -1; + + int *solution = malloc(numCoins * sizeof(int)); + if(solution == NULL) return NULL; + + memset(solution, 0, nC); //Initialize solution to 0 + + while(accumChange != amount){ + while(nC>=0 && coins[nC] > (amount - accumChange)) + nC--; + + if(nC < 0){ + return NULL; + }else{ + solution[nC] = (amount - accumChange) / coins[nC]; + accumChange += coins[nC] * solution[nC]; + } + } + return solution; + +} diff --git a/Algoritmic Schemes/Voracious Algorithms/Coin Change Machine/chm.h b/Algoritmic Schemes/Voracious Algorithms/Coin Change Machine/chm.h new file mode 100644 index 0000000..a95b1de --- /dev/null +++ b/Algoritmic Schemes/Voracious Algorithms/Coin Change Machine/chm.h @@ -0,0 +1,7 @@ +#ifndef __CHM_H__ +#define __CHM_H__ + +int *coinsChange(int amount, int *coins,int numCoins); +int *coinsChangeV2(int amount, int *coins, int numCoins); + +#endif diff --git a/Algoritmic Schemes/Voracious Algorithms/Coin Change Machine/main.c b/Algoritmic Schemes/Voracious Algorithms/Coin Change Machine/main.c new file mode 100644 index 0000000..8f5abd5 --- /dev/null +++ b/Algoritmic Schemes/Voracious Algorithms/Coin Change Machine/main.c @@ -0,0 +1,59 @@ +#include +#include + +#include "chm.h" + + +int main(int argc, char **argv){ + int i; + + int numCoins = 8; //Change numCoins according to coins length + + //Coins in cts(€) -> 1cts to 200cts(or 2€) + int coins[8]={1,2,5,10,20,50,100,200}; //€ + //int coins[6]={1,3,6,12,24,30}; //Old english monetary system + + printf("COINS AVAILABLE\n"); + for(i=0; i +#include + +#include "primeFact.h" + +#define NUMPRIMES 20 + +int main(int argc, char **argv){ + + int primes[NUMPRIMES]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71}; + int solution[NUMPRIMES], primesTried; + int number = 600; + + primesTried = primeFactorization(number, primes, NUMPRIMES, solution); + + int i; + printf("\nPRIMES USED\n"); + for(i=0; i +#include + +#include "primeFact.h" + +/* Voracious algorithm that returns a solution for a number factorization + * using an array of primes (its imposible to use all infinite primes) + * It also returns the number of primes that are used to factorize the + * number. That is, if it uses numbers 2,3,5,7 (all 2 times) to factorize + * the number, it will return 4 (one for 2, one for 3, one for 5, one for 7) + */ +int primeFactorization(int number, int *primes, int numPrimes, int *solution){ + if(solution == NULL || primes == NULL || numPrimes<=0) return -1; + + int j; + for(j=0; j= numPrimes) + return 0; + + else{ + solution[j]++; + total /= primes[j]; + + } + } + + int numPrimesFinded = 0; + for(j=0; j +#include +#include + +int *createArray(int size); +int *createSortedArray(int size); +void printArray(int *array, int arraySize); + + + + + + +#endif diff --git a/Search algorithms/main.c b/Search algorithms/main.c new file mode 100644 index 0000000..bd92750 --- /dev/null +++ b/Search algorithms/main.c @@ -0,0 +1,39 @@ +#include +#include +#include + +#include "arraysUtility.h" +#include "searchAlgorithms.h" + +int main(int argc, char **argv){ + + int valueToFind; + int arraySize; + + printf("Array size?:"); + scanf("%d%*c",&arraySize); + + //int *array = createArray(arraySize); //Not binary search + int *array = createSortedArray(arraySize); //Any search + + if(array == NULL) + return -1; + + printArray(array,arraySize); + printf("\n"); + + printf("\nValue?:"); + scanf("%d%*c",&valueToFind); + + //int pos = linearSearch(valueToFind,array,arraySize); + //int pos = binarySearch(valueToFind,array,arraySize); + int pos = binaryRecursiveSearch(valueToFind,array,0,arraySize-1); + + if(pos == -1) + printf("\nCan not find value %d in the array\n",valueToFind); + else + printf("\nValue %d finded at pos %d\n",valueToFind, pos); + + return 0; +} + diff --git a/Search algorithms/makefile b/Search algorithms/makefile new file mode 100644 index 0000000..af072d4 --- /dev/null +++ b/Search algorithms/makefile @@ -0,0 +1,26 @@ +CC=gcc +CFLAGS=-c +#CFLAGS=-c -g +EJECUTABLE_NAME=eje + +all: $(EJECUTABLE_NAME) + +$(EJECUTABLE_NAME): main.o searchAlgorithms.o arraysUtility.o + $(CC) $^ -o $@ + +main.o: main.c + $(CC) $(CFLAGS) main.c + +searchAlgorithms.o: searchAlgorithms.c searchAlgorithms.h + $(CC) $(CFLAGS) searchAlgorithms.c + +arraysUtility.o: arraysUtility.c arraysUtility.h + $(CC) $(CFLAGS) arraysUtility.c + +#%.o: %.c %.h +# $(CC) -c %.c + + +clean: + rm *.o + rm $(EJECUTABLE_NAME) diff --git a/Search algorithms/searchAlgorithms.c b/Search algorithms/searchAlgorithms.c new file mode 100644 index 0000000..af78aeb --- /dev/null +++ b/Search algorithms/searchAlgorithms.c @@ -0,0 +1,73 @@ +#include "searchAlgorithms.h" + +/* Sequential search that looks each element from the first one + * until it founds the value or until the vector finishes + * + * Returns index where the value is located in the array. + */ +int linearSearch(int value, int *array, int arraySize){ + int i; + for(i=0; i array[k]){ + i = k+1; + + }else if(value == array[k]){ + i = k; + j = k; + } + } + + if(value == array[i]) return i; + else return -1; +} + + +/* + * Recursive implementation of the binary search + */ +int binaryRecursiveSearch(int value, int *array, int firstElement, int lastElement){ + if(firstElement > lastElement) + return -1; + + else{ + int i = firstElement; + int j = lastElement; + int k=(i+j)/2; + if(value < array[k]){ + j = k-1; + + }else if(value > array[k]){ + i = k+1; + + }else if(value == array[k]){ + return k; + } + + return binaryRecursiveSearch(value,array,i,j); + } +} diff --git a/Search algorithms/searchAlgorithms.h b/Search algorithms/searchAlgorithms.h new file mode 100644 index 0000000..1af4e00 --- /dev/null +++ b/Search algorithms/searchAlgorithms.h @@ -0,0 +1,8 @@ +#ifndef __SEARCH_ALGORITHMS__ +#define __SEARCH_ALGORITHMS__ + +int linearSearch(int value, int *array, int arraySize); +int binarySearch(int value, int *array, int arraySize); +int binaryRecursiveSearch(int value, int *array, int firstElement, int lastElement); + +#endif diff --git a/Sorting Algorithms/arraysListsUtilities.c b/Sorting Algorithms/arraysListsUtilities.c new file mode 100644 index 0000000..3f21da7 --- /dev/null +++ b/Sorting Algorithms/arraysListsUtilities.c @@ -0,0 +1,116 @@ +#include "arraysListsUtilities.h" + +int *createArray(int size){ + if(size <=0) + return NULL; + + + int *array; + if(NULL == (array=malloc(size * sizeof(int)))){ + #ifdef DEBUG + fprintf(stderr,"Error: Can not reserve memory for array\n"); + #endif + return NULL; + } + + srand(time(NULL)); + for(int i=0; iinfo = info; + new->next = NULL; + return new; +} + + +void createList(Node **list, int numNodes){ + if(*list==NULL){ + int i; + Node *new=NULL, *last=NULL; + + srand(time(NULL)); + for(i=0; inext = new; + last=new; + } + new=NULL; + } + } +} + +void printList(Node *list){ + Node *aux=list; + while(aux!=NULL){ + printf("%d ", aux->info); + aux = aux->next; + } +} + + + + + + + + + + + + + + + diff --git a/Sorting Algorithms/arraysListsUtilities.h b/Sorting Algorithms/arraysListsUtilities.h new file mode 100644 index 0000000..1e23655 --- /dev/null +++ b/Sorting Algorithms/arraysListsUtilities.h @@ -0,0 +1,25 @@ +#ifndef __ARRAYS_UTILITY__ +#define __ARRAYS_UTILITY__ + +#include +#include +#include + +//Arrays utilities +int *createArray(int size); +int *createSortedArray(int size); +void printArray(int *array, int arraySize); + +void swap(int *array, int i, int j); + +//Lists utilities +typedef struct node{ + int info; + struct node *next; +}Node; + +Node* createNode(int info); +void createList(Node **list, int numNodes); +void printList(Node *list); + +#endif diff --git a/Sorting Algorithms/main.c b/Sorting Algorithms/main.c new file mode 100644 index 0000000..f49ee12 --- /dev/null +++ b/Sorting Algorithms/main.c @@ -0,0 +1,71 @@ +#include +#include + +#include "arraysListsUtilities.h" +#include "sortingAlgorithms.h" + +int main(int argc, char **argv){ + + int arraySize; + + printf("Array size?:"); + scanf("%d%*c",&arraySize); + + int *array = createArray(arraySize); + + if(array == NULL) + return -1; + + printf("\nRandom array\n"); + printArray(array,arraySize); + + //bubbleSort(array,arraySize); + //selectionSort(array,arraySize); + //insertionSort(array,arraySize); + + //int inc[5] = {1,2,3,4,5}; + //shellSort(array,arraySize,inc,5); + + //quickSort(array,0,arraySize-1); + //mergeSort(array,0,arraySize-1); + + printf("\n\nSortered array\n"); + printArray(array,arraySize); + + puts("\n"); + + + //Comment the code before and uncomment this for radix sort + /* + int numNodes; + int numGroups = 10; //decimal, 10 numbers, 0-9 + + printf("List size?:"); + scanf("%d%*c",&numNodes); + + int numFigures=0; + int aux = numNodes-1; + //This loop will calculate the number of figures the biggest number has. + // createList method just create nodes with info from 0 to numNodes-1 + // so is easy to know the max number of figures the numbers have. + while(aux != 0){ + numFigures++; + aux = aux/10; + } + + Node* list=NULL; + createList(&list, numNodes); + + printf("\nRandom list\n"); + printList(list); + + radixSortLSD(&list,numGroups,numFigures); + + printf("\n\nSorted list with RadixSort\n"); + printList(list); + + puts("\n\n"); + */ + return 0; +} + diff --git a/Sorting Algorithms/makefile b/Sorting Algorithms/makefile new file mode 100644 index 0000000..9e13b6c --- /dev/null +++ b/Sorting Algorithms/makefile @@ -0,0 +1,26 @@ +CC=gcc +#CFLAGS=-c +CFLAGS=-c -g +EXECUTABLE_NAME=eje + +all: $(EXECUTABLE_NAME) + +$(EXECUTABLE_NAME): main.o sortingAlgorithms.o arraysListsUtilities.o + $(CC) $^ -o $@ -lm + +main.o: main.c + $(CC) $(CFLAGS) main.c + +sortingAlgorithms.o: sortingAlgorithms.c sortingAlgorithms.h + $(CC) $(CFLAGS) sortingAlgorithms.c + +arraysListsUtilities.o: arraysListsUtilities.c arraysListsUtilities.h + $(CC) $(CFLAGS) arraysListsUtilities.c + +#%.o: %.c %.h +# $(CC) -c %.c + + +clean: + rm *.o + rm $(EXECUTABLE_NAME) diff --git a/Sorting Algorithms/sortingAlgorithms.c b/Sorting Algorithms/sortingAlgorithms.c new file mode 100644 index 0000000..8d2ee54 --- /dev/null +++ b/Sorting Algorithms/sortingAlgorithms.c @@ -0,0 +1,261 @@ +#include "sortingAlgorithms.h" + +/* Sorts the array bubbling each element to his correct + * position. O(n²) + */ +void bubbleSort(int *array, int arraySize){ + int i,j; + + for(i=0; i<=arraySize-2; i++){ + for(j=arraySize-2; j>=i; j--){ + if(array[j] > array[j+1]){ + swap(array,j,j+1); + } + } + } + +} + + +/* Select the lowest element and put it in his correct + * position. O(n²) + */ +void selectionSort(int *array, int arraySize){ + int i,j; + int posSelection; + typeof(array[0]) valueSelection; + + for(i=0; i<=arraySize-2; i++){ + posSelection = i; + + for(j=i+1; j<=arraySize-1; j++){ + if(array[j] < array[posSelection]){ + posSelection = j; + } + } + + swap(array, posSelection, i); + } +} + +/* Inserts the first element of the array in his correct + * position (elements are cycling to the first position + * until they are all in their correct position) + * O(n²) worst/average cases + * O(n) best case + */ +void insertionSort(int *array, int arraySize){ + int i,j; + typeof(array[0]) temp; + + for(i=1; i<=arraySize-1; i++){ + temp = array[i]; + j = i-1; + while(j>=0 && array[j]>temp){ + swap(array, j, j+1); + j--; + } + array[j + 1] = temp; + } +} + + + +/* Inprovement of "insertionSort". + * Divides the array in subarrays using gaps (array with + * the length of the subarrays) and the sorting that + * subarrays using insertion sort. + * The complexity of this alg depends on the gaps. + */ +void shellSort(int *array, int arraySize, int *gaps, int numGaps){ + int gap, i, j; + typeof(gaps[0]) h; + typeof(array[0]) temp; + + for(gap=numGaps-1; gap>=0; gap--){ + h = gaps[gap]; + for(i=h; i<=arraySize-1; i++){ + temp = array[i]; + j= i-h; + while(j>=0 && array[j] > temp){ + swap(array, j+h, j); + j -= h; + } + array[j+h] = temp; + } + } +} + + + + +/* Recursive algorithm that uses a pivot and putting all the + * elements that are smaller than the pivot in the left of + * the pivot and all the elements that are bigger in the right, + * and then sort this 2 subarrays using recursivity. + * O(n²) worst case + * O(nlg(n)) best/average cases + */ +void quickSort(int *array, int base, int top){ + if(base < top){ + int pivot = selectPivot(array,base,top); + quickSort(array, base, pivot-1); + quickSort(array, pivot+1, top); + } +} + +//Selects the first element as the pivot +int selectPivot(int *array, int base, int top){ + int pivot = base; + int pivotValue = array[base]; + int i; + + for(i=base+1; i<=top; i++){ + if(array[i] < pivotValue){ + pivot++; + swap(array, pivot, i); + } + } + swap(array, base, pivot); + return pivot; +} + + + +/* Recursive algorithm that separates an array into 2 subarrays + * that will be merged later in ascending order. + * O(nlg(n)) all cases + */ +void mergeSort(int *array, int base, int top){ + if(base < top){ + int middle = (base+top)/2; + mergeSort(array, base, middle); + mergeSort(array, middle+1, top); + merge(array, base, middle, middle+1, top); + } +} + +//Merges the subarrays in ascending order +void merge(int *array, int baseA, int topA, int baseB, int topB){ + int i; + int dimA = topA - baseA +1; + int dimB = topB - baseB +1; + + //Temp arrays + int A[dimA], B[dimB]; + for(i=0; iinfo, posFigure); + if(groups[c] == NULL){ + groups[c] = aux; + lasts[c] = aux; + }else{ + lasts[c]->next = aux; + lasts[c] = aux; + } + aux = aux->next; + lasts[c]->next = NULL; + } + *list = NULL; +} + +//Concatenates all groups (0-9) in ascending order. This causes the numbers +// to be ordered according with and specific figure. +void concat(Node **list, Node **groups, Node **lasts, int numGroups){ + int k,prev; + + *list = NULL; + for(k=0; knext = groups[k]; + } + prev = k; + } + } + lasts[prev]->next = NULL; +} + +// Extracts figure in a specific position from a number +int extractFigure (int num, int posFigure){ + int d, c, figure; + + d = pow(10, posFigure-1); + c = num / d; + figure = c % 10; + + return figure; +} + + + + + + diff --git a/Sorting Algorithms/sortingAlgorithms.h b/Sorting Algorithms/sortingAlgorithms.h new file mode 100644 index 0000000..a2f1e77 --- /dev/null +++ b/Sorting Algorithms/sortingAlgorithms.h @@ -0,0 +1,28 @@ +#ifndef __SORTING_ALGORITHMS__ +#define __SORTING_ALGORITHMS__ + +#include +#include "arraysListsUtilities.h" + +void bubbleSort(int *array, int arraySize); +void selectionSort(int *array, int arraySize); +void insertionSort(int *array, int arraySize); +//TODO: insertionSort with binary search instead of linear search +void shellSort(int *array, int arraySize, int *gaps, int numGaps); + +//QuickSort +void quickSort(int *array, int base, int top); +int selectPivot(int *array, int base, int top); + +//MergeSort +void mergeSort(int *array, int base, int top); +void merge(int *array, int baseA, int topA, int baseB, int topB); + +//RadixSort +void radixSortLSD(Node **list,int numGroups,int numFigures); +void distribute(int posFigure, Node **list, Node** groups, Node **lasts); +void concat(Node **list, Node **groups, Node **lasts, int numGroups); +int extractFigure (int num, int posFigure); + + +#endif