1 var sudoku = require('sudoku');
2 var _ = require("lodash")
24 const isValidMap = (map) => {
25 // B9 + B8 + C1 + H4 + H4 = 23
26 if (map[B][N9] + map[B][N8] + map[C][N1] + map[H][N4] + map[H][N4] !== 23) {
30 // A5 + D7 + I5 + G8 + B3 + A5 = 19
31 if (map[A][N5] + map[D][N7] + map[I][N5] + map[G][N8] + map[B][N3] + map[A][N5] !== 19) {
35 // I2 + I3 + F2 + E9 = 15
36 if (map[I][N2] + map[I][N3] + map[F][N2] + map[E][N9] !== 15) {
40 // I7 + H8 + C2 + D9 = 26
41 if (map[I][N7] + map[H][N8] + map[C][N2] + map[D][N9] !== 26) {
45 // I6 + A5 + I3 + B8 + C3 = 20
46 if (map[I][N6] + map[A][N5] + map[I][N3] + map[B][N8] + map[C][N3] !== 20) {
50 // I7 + D9 + B6 + A8 + A3 + C4 = 27
51 if (map[I][N7] + map[D][N9] + map[B][N6] + map[A][N8] + map[A][N3] + map[C][N4] !== 27) {
55 // C7 + H9 + I7 + B2 + H8 + G3 = 31
56 if (map[C][N7] + map[H][N9] + map[I][N7] + map[B][N2] + map[H][N8] + map[G][N3] !== 31) {
60 // D3 + I8 + A4 + I6 = 27
61 if (map[D][N3] + map[I][N8] + map[A][N4] + map[I][N6] !== 27) {
65 // F5 + B8 + F8 + I7 + F1 = 33
66 if (map[F][N5] + map[B][N8] + map[F][N8] + map[I][N7] + map[F][N1] !== 33) {
70 // A2 + A8 + D7 + E4 = 21
71 if (map[A][N2] + map[A][N8] + map[D][N7] + map[E][N4] !== 21) {
75 // C1 + I4 + C2 + I1 + A4 = 20
76 if (map[C][N1] + map[I][N4] + map[C][N2] + map[I][N1] + map[A][N4] !== 20) {
80 // F8 + C1 + F6 + D3 + B6 = 25
81 if (map[F][N8] + map[C][N1] + map[F][N6] + map[D][N3] + map[B][N6] !== 25) {
89 null, null, null, null, null, null, null, null, 1,
90 null, 1, 2, null, null, null, null, null, null,
91 null, null, null, null, null, null, 2, null, null,
92 null, null, null, null, null, null, null, null, 2,
93 null, 2, null, null, null, null, null, null, null,
94 null, null, null, null, null, null, null, null, null,
95 null, null, null, null, null, null, 1, 2, null,
96 1, null, null, null, null, 2, null, null, null,
97 null, null, null, 1, null, null, null, null, null];
99 let solution = _.chunk(sudoku.solvepuzzle(puzzle), 9);
100 while (!isValidMap(solution)) {
101 solution = _.chunk(sudoku.solvepuzzle(puzzle), 9);
104 console.log(solution)