summaryrefslogtreecommitdiff
path: root/solver.c
diff options
context:
space:
mode:
authorolivier gayot <ogayot@free.fr>2012-12-13 11:54:29 +0000
committerolivier gayot <ogayot@free.fr>2012-12-13 11:54:55 +0000
commiteeb456d954b90c8f1c9247d91afde52d690778ff (patch)
treeb9429e363482202bd4b905cb3ff6f1bbeeb71b95 /solver.c
parent88ba8ead742537c369c228953a2b2a88efd021f5 (diff)
le_compte_est_bon: make the solver work with any number of arguments
Diffstat (limited to 'solver.c')
-rw-r--r--solver.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/solver.c b/solver.c
index 334848e..27de4ca 100644
--- a/solver.c
+++ b/solver.c
@@ -12,10 +12,10 @@
typedef uint8_t byte;
enum {
- addition,
- substraction,
- multiplication,
- division,
+ addition ,
+ substraction ,
+ multiplication ,
+ division ,
};
typedef struct {
@@ -30,6 +30,7 @@ typedef struct {
} solution_t;
static solution_t solution_g;
+static vect_t *vect_g;
static int result;
static int closer = -1;
@@ -38,10 +39,9 @@ static int closer = -1;
static void display_solution(void)
{
- puts("--------------------------");
puts("found a (better) solution:");
- for (int i = 5; i >= solution_g.level; i--) {
+ for (int i = vect_g->len - 1; i >= solution_g.level; i--) {
char op;
int _result;
@@ -72,6 +72,7 @@ static void display_solution(void)
, solution_g.computation[i].v2
, _result);
}
+ puts("--------------------------");
}
/* }}} */
@@ -161,13 +162,16 @@ static void solve_rec(vect_t *vect)
/* public function to use */
void solve(vect_t *vect, int _result)
{
+ vect_g = vect;
result = _result;
solution_g.computation = malloc(sizeof(computation_t) * vect->len);
solution_g.level = 0;
solve_rec(vect);
- if (closer != result) {
+ if (closer == result) {
+ puts("Le compte est bon!");
+ } else {
result = closer;
closer = -1;
solve_rec(vect);