Skip to content

Commit 2b8e9ef

Browse files
authored
Merge pull request loiane#51 from loiane/third-edition
Third edition
2 parents 90aaa3c + ba52bc9 commit 2b8e9ef

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

examples/PacktDataStructuresAlgorithms.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/PacktDataStructuresAlgorithms.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/index.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ export const util = _util;
66
// chapter 03
77
export { default as StackArray } from './data-structures/stack-array';
88
export { default as Stack } from './data-structures/stack';
9-
export { default as hanoi } from './others/hanoi';
10-
export { default as hanoiStack } from './others/hanoi';
11-
export { default as baseConverter } from './others/base-converter';
12-
export { default as decimalToBinary } from './others/base-converter';
13-
export { default as parenthesesChecker } from './others/balanced-symbols';
9+
export { hanoi } from './others/hanoi';
10+
export { hanoiStack } from './others/hanoi';
11+
export { baseConverter } from './others/base-converter';
12+
export { decimalToBinary } from './others/base-converter';
13+
export { parenthesesChecker } from './others/balanced-symbols';
1414

1515
// chapter 04
1616
export { default as Queue } from './data-structures/queue';

src/ts/algorithms/backtracking/rat-in-maze.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function ratInAMaze(maze: Array<Array<number>>) {
88
}
99
}
1010

11-
if (findPath(maze, 0, 0, solution) === false) {
11+
if (findPath(maze, 0, 0, solution) === true) {
1212
return solution;
1313
} else {
1414
return 'NO PATH FOUND';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'mocha';
2+
import { expect } from 'chai';
3+
import { ratInAMaze } from '../../../../src/ts/index';
4+
5+
describe('Rat in a maze', () => {
6+
it('rat in a maze solver', () => {
7+
const maze = [
8+
[1, 0, 0, 0],
9+
[1, 1, 1, 1],
10+
[0, 0, 1, 0],
11+
[0, 1, 1, 1]
12+
];
13+
const solution = [
14+
[1, 0, 0, 0],
15+
[1, 1, 1, 0],
16+
[0, 0, 1, 0],
17+
[0, 0, 1, 1]
18+
];
19+
expect(ratInAMaze(maze)).to.deep.equal(solution);
20+
});
21+
});

test/ts/algorithms/backtracking/sudoku-solver.spec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,30 @@ describe('Sudoku Solver', () => {
2828
];
2929
expect(sudokuSolver(grid)).to.deep.equal(solution);
3030
});
31+
32+
it('sudoku solver 2', () => {
33+
const grid = [
34+
[5, 3, 0, 0, 7, 0, 0, 0, 0],
35+
[6, 0, 0, 1, 9, 5, 0, 0, 0],
36+
[0, 9, 8, 0, 0, 0, 0, 6, 0],
37+
[8, 0, 0, 0, 6, 0, 0, 0, 3],
38+
[4, 0, 0, 8, 0, 3, 0, 0, 1],
39+
[7, 0, 0, 0, 2, 0, 0, 0, 6],
40+
[0, 6, 0, 0, 0, 0, 2, 8, 0],
41+
[0, 0, 0, 4, 1, 9, 0, 0, 5],
42+
[0, 0, 0, 0, 8, 0, 0, 7, 9]
43+
];
44+
const solution = [
45+
[5, 3, 4, 6, 7, 8, 9, 1, 2],
46+
[6, 7, 2, 1, 9, 5, 3, 4, 8],
47+
[1, 9, 8, 3, 4, 2, 5, 6, 7],
48+
[8, 5, 9, 7, 6, 1, 4, 2, 3],
49+
[4, 2, 6, 8, 5, 3, 7, 9, 1],
50+
[7, 1, 3, 9, 2, 4, 8, 5, 6],
51+
[9, 6, 1, 5, 3, 7, 2, 8, 4],
52+
[2, 8, 7, 4, 1, 9, 6, 3, 5],
53+
[3, 4, 5, 2, 8, 6, 1, 7, 9]
54+
];
55+
expect(sudokuSolver(grid)).to.deep.equal(solution);
56+
});
3157
});

0 commit comments

Comments
 (0)