-
Notifications
You must be signed in to change notification settings - Fork 0
/
piles.js
58 lines (48 loc) · 1.37 KB
/
piles.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
51
52
53
54
55
56
57
58
function addPiles(pile1, pile2) {
let _pile1 = copy(pile1);
const l = _pile1.length;
for (let j = 0; j < l; j++) {
for (let i = 0; i < l; i++) {
_pile1[i][j] += pile2[i][j];
}
}
return reduceTillCompleteFast(_pile1);
}
function addPilesAnimate(pile1, pile2, options) {
let _pile1 = copy(pile1);
const l = _pile1.length;
for (let j = 0; j < l; j++) {
for (let i = 0; i < l; i++) {
_pile1[i][j] += pile2[i][j];
}
}
return reduceAnimate(_pile1, options);
}
function subPiles(pile1, pile2) {
let _pile1 = copy(pile1);
const l = _pile1.length;
for (let j = 0; j < l; j++) {
for (let i = 0; i < l; i++) {
_pile1[i][j] -= pile2[i][j];
}
}
return reduceTillCompleteFast(_pile1);
}
function subPilesAnimate(pile1, pile2, options) {
let _pile1 = copy(pile1);
const l = _pile1.length;
for (let j = 0; j < l; j++) {
for (let i = 0; i < l; i++) {
_pile1[i][j] -= pile2[i][j];
}
}
return reduceAnimate(_pile1, options);
}
function getInfPileWidth(pile) {
const centerindex = (pile.length + 1) >> 1;
let lastSigIndex = pile.length - 1;
for (let i = centerindex; i < pile.length; i++) {
if (pile[centerindex][i] !== 0) lastSigIndex = i;
}
return Math.abs(centerindex - lastSigIndex);
}