rename sudoku constants to shorter names

This commit is contained in:
2025-07-30 13:14:30 +02:00
parent 0453c21a3c
commit 4c707a0fa6
3 changed files with 11 additions and 11 deletions

View File

@@ -7,7 +7,7 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
(void)argc, (void)argv; (void)argc, (void)argv;
u16 board[SUDOKU_DEPTH_2] = { u16 board[SUDOKU_LEN] = {
// clang-format off // clang-format off
0x010, 0x004, 0x000, 0x000, 0x040, 0x000, 0x000, 0x000, 0x000, 0x010, 0x004, 0x000, 0x000, 0x040, 0x000, 0x000, 0x000, 0x000,
0x020, 0x000, 0x000, 0x001, 0x100, 0x010, 0x000, 0x000, 0x000, 0x020, 0x000, 0x000, 0x001, 0x100, 0x010, 0x000, 0x000, 0x000,

View File

@@ -14,18 +14,18 @@ static inline void setbrdpos(u16 *brd, u16 val) {
} }
void sudoku_place(u16 *brd, u16 val, uint idx) { void sudoku_place(u16 *brd, u16 val, uint idx) {
uint icol = idx % SUDOKU_DEPTH; uint icol = idx % SUDOKU_DPT;
uint irow = idx - icol; uint irow = idx - icol;
uint ibox = idx - (idx % SUDOKU_DEPTH_SQRT); uint ibox = idx - (idx % SUDOKU_BOXLEN);
for (uint i = 0; i < SUDOKU_DEPTH; i++) { for (uint i = 0; i < SUDOKU_DPT; i++) {
setbrdpos(&brd[irow + i], val); setbrdpos(&brd[irow + i], val);
setbrdpos(&brd[icol + (i * SUDOKU_DEPTH)], val); setbrdpos(&brd[icol + (i * SUDOKU_DPT)], val);
setbrdpos(&brd[ibox + (i / SUDOKU_DEPTH_SQRT * SUDOKU_DEPTH) + (i % SUDOKU_DEPTH_SQRT)], val); setbrdpos(&brd[ibox + (i / SUDOKU_BOXLEN * SUDOKU_DPT) + (i % SUDOKU_BOXLEN)], val);
} }
} }
void sudoku_solve_step(u16 *board) { void sudoku_solve_step(u16 *board) {
for (uint i = 0; i < SUDOKU_DEPTH_2; i++) { for (uint i = 0; i < SUDOKU_LEN; i++) {
board[i] |= SUDOKU_ALL & -!board[i]; board[i] |= SUDOKU_ALL & -!board[i];
switch (board[i]) { switch (board[i]) {
@@ -45,7 +45,7 @@ void sudoku_solve_step(u16 *board) {
void sudoku_print(const u16 *board) { void sudoku_print(const u16 *board) {
printf("+———-———-———-———-———-———-———-———-———+\n"); printf("+———-———-———-———-———-———-———-———-———+\n");
for (uint i = 0; i < SUDOKU_DEPTH_2; i++) { for (uint i = 0; i < SUDOKU_LEN; i++) {
char tile; char tile;
switch (board[i]) { switch (board[i]) {
case 0: tile = 'x'; break; case 0: tile = 'x'; break;

View File

@@ -4,9 +4,9 @@
#include "util/intdef.h" #include "util/intdef.h"
#define SUDOKU_DEPTH_SQRT 3 #define SUDOKU_BOXLEN 3
#define SUDOKU_DEPTH (SUDOKU_DEPTH_SQRT * SUDOKU_DEPTH_SQRT) #define SUDOKU_DPT 9
#define SUDOKU_DEPTH_2 (SUDOKU_DEPTH * SUDOKU_DEPTH) #define SUDOKU_LEN (SUDOKU_DPT * SUDOKU_DPT)
/* bitmask */ /* bitmask */
enum sudoku_bitmask { enum sudoku_bitmask {