-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawingBook.js
52 lines (41 loc) · 956 Bytes
/
drawingBook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// 6,2 >> 1
// [][1] > [2][3]
// [6][] > [4][5] > [2][3]
// 6, 6 >> 0
// [6][]
// [][6]
// 6, 5 >> 1
// [][1] > [2][3] > [4][5] > [6][]
// [6][] > [5][4]
// 1, 3 >> 0
// [][1]
// [2][3] > [][1]
// 3, 1 >> 0
// [0][1]
// [2][3] > [][1]
// 5, 1
// [0][1]
void function () {
const tests = [
[6, 2], [6, 6], [6, 5],
[1, 3], [3, 1], [0, 0],
[1, 1], [70809, 46090],
[5, 1], [21235, 17], [2, 1],
];
const res = [1, 0, 1, 0, 0, 0, 0, 12359, 0, 8, 0];
let i = 0;
let out = '';
for (let test of tests) {
if (pageCount(...test) !== res[i]) {
out += `Test ${i}: ${test} [${res[i]} != ${pageCount(...test)}]\n`;
}
i++;
}
console.log(out);
}();
function pageCount(n, p) {
if (n <= 1 || p <= 1) return 0;
if (n % 2 == 0 && n - p == 1) return 1;
if (n - p == 1 || n == p) return 0;
return Math.min(Math.floor(p / 2), Math.floor((n - p) / 2));
}