Add load() for loading sudokus from text

This commit is contained in:
2022-11-23 22:17:38 +00:00
parent 0ca01985cd
commit 9bc49daf4c
2 changed files with 19 additions and 0 deletions

12
sud.c
View File

@@ -35,6 +35,18 @@ static void initposs(struct sudoku *sud)
}
}
bool load(struct sudoku *sud, const char *ptr)
{
initposs(sud);
for (unsigned i = 0; i < NCELLS; ++i) {
if (ptr[i] == '0')
continue;
if (update(sud, i / NDIGITS, i % NDIGITS, ptr[i] - '1') != OK)
return false;
}
return true;
}
static void clear(struct sudoku *sud, unsigned r, unsigned c)
{
unsigned tr, tc, val;