-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixGenerator.js
More file actions
41 lines (32 loc) · 853 Bytes
/
MatrixGenerator.js
File metadata and controls
41 lines (32 loc) · 853 Bytes
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
function MatrixGenerator() {
this.createMatrix = function() {
let i, j, k;
let cards = [] //the deck of cards
let card = []; //to start, we build the first card
for (i = 1; i <= n + 1; i++) {
card.push(i)
}
cards.push(card)
//then we build the next n number of cards
for (j = 1; j <= n; j++) {
card = []
card.push(1)
for (k = 1; k <= n; k++) {
card.push(n * j + (k + 1))
}
cards.push(card)
}
//finally we build the next n² number of cards
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
card = []
card.push(i + 1)
for (k = 1; k <= n; k++) {
card.push(n + 2 + n * (k - 1) + (((i - 1) * (k - 1) + j - 1) % n))
}
cards.push(card)
}
}
return cards;
}
}