Make fill proportion a parameter to gen()
This commit is contained in:
9
sud.c
9
sud.c
@@ -22,9 +22,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define REM_PROB_NUMER 2
|
||||
#define REM_PROB_DENOM 3
|
||||
|
||||
#define MAX_FILL_ATTEMPTS 32
|
||||
|
||||
static void initposs(struct sudoku *sud)
|
||||
@@ -76,7 +73,7 @@ static void clear(struct sudoku *sud, unsigned r, unsigned c)
|
||||
}
|
||||
}
|
||||
|
||||
void gen(struct sudoku *sud)
|
||||
void gen(struct sudoku *sud, double fill_prop)
|
||||
{
|
||||
/* Generate a completed sudoku. */
|
||||
retry:
|
||||
@@ -93,10 +90,10 @@ retry:
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove cells with probability of `1 / REMOVE_PROB_RECIP`. */
|
||||
/* Remove cells with probability of 1 - fill_prop. */
|
||||
for (unsigned r = 0; r < NDIGITS; ++r) {
|
||||
for (unsigned c = 0; c < NDIGITS; ++c) {
|
||||
if (rand() % REM_PROB_DENOM < REM_PROB_NUMER)
|
||||
if ((double)rand() / (double)RAND_MAX < 1 - fill_prop)
|
||||
clear(sud, r, c);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user