Skip to content

Commit 46c726f

Browse files
committed
Change returned array in attachPossibleNumbers, implement eliminateRowNumbers
1 parent 0fd8f24 commit 46c726f

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/lib/implications.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1+
import { getColumn, getSector } from './commons';
12

23
const availableNumbers = [1,2,3,4,5,6,7,8,9];
34

45
const attachPossibleNumbers = (board) => (
56
// takes a sudoku board and returns a 9x9 matrix with each
6-
// cell being an object that contains the number on the board and an
7-
// array with all the available numbers to fill the cell with.
7+
// cell containing an array with all the available numbers to fill the cell with.
88
board.map( row => (
9-
row.map( cell => ({
10-
data: cell,
11-
possibleNumbers: (cell===0) ? availableNumbers : []
12-
}))
9+
row.map( cell => (
10+
(cell===0) ? availableNumbers : []
11+
))
1312
))
1413
);
1514

16-
export { attachPossibleNumbers };
15+
const eliminateRowNumbers = (board, possibleNumbers) => (
16+
// for each cell's possible numbers, it eliminates nums that appear elsewhere in the same row
17+
possibleNumbers.map( (row,rowIndex) => (
18+
row.map( cellNums =>
19+
cellNums.filter( num => !board[rowIndex].includes(num) )
20+
)
21+
))
22+
);
23+
24+
export { attachPossibleNumbers, eliminateRowNumbers };

0 commit comments

Comments
 (0)