-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconflict_problem.js
More file actions
143 lines (120 loc) · 4.13 KB
/
Copy pathconflict_problem.js
File metadata and controls
143 lines (120 loc) · 4.13 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
let satArr = [
// 08:00 - 09:30
['ITSE312 (A)', 'ITGS111 (A)'],
// 09:30 - 11:00
['ITSE413 (A)', 'ITGS113 (A)'],
// 11:00 - 12:30
['ITSE414 (A)', 'ITIS413 (A)'],
// 12:30 - 14:00
['ITGS122 (B)'],
// 14:00 - 15:30
['ITGS223 (B)'],
// 15:30 - 17:00
['ITEL111 (A)'],
];
let sunArr = [
['ITGS111 (A)'],
['ITSE401 (A)'],
['ITSE405 (A)'],
['ITSE411 (A)'],
['ITGS223 (A)', 'ITGS223 (B)'],
[],
];
let allSubjectsArr = [satArr, sunArr];
let allSubjectsArrFlatten = [].concat(...[...satArr, ...sunArr]);
let uniqueGroupSubjects = [...new Set(allSubjectsArrFlatten)];
// Take each unique groupSubject, ex: ITEN111 (A)
// for(let i=0; i<uniqueGroupSubjects.length; i++) {
// let singleGroupSubject = uniqueGroupSubjects[i];
// // See which day&time this unique subject is repeated in, ex: day 0, time 1 & day 1, time 2
// for(let day=0; day<allSubjectsArr.length; day++) {
// for(let time=0; time<allSubjectsArr[day].length; time++) {
// for(let times=0; times<allSubjectsArr[day][time].length; times++) {
// if(singleGroupSubject == allSubjectsArr[day][time][times]) console.log(`${singleGroupSubject} is in: Day:${day}, Time:${time}`)
// }
// }
// }
// }
let userSubjctsArr = [['ITGS111 (A)'], ['ITGS223 (A)', 'ITGS223 (B)']];
/* (2) Get days times of each subject, output ex:
[
[
[[0,1],[1,0]], "Single SubjectGroup Days&Times"
],
[
[[0,1],[1,0]],
[[0,1],[1,0]]
],
]
*/
let arrayDaysTimes = getArrayDaysTimes(userSubjctsArr);
function getArrayDaysTimes(userSubjctsArr) {
let arrayDaysTimes = [];
for(let i=0; i<userSubjctsArr.length; i++) {
let arrayDaysTimesMany = [];
for(let j=0; j<userSubjctsArr[i].length; j++) {
// See which day&time this unique subject is repeated in, ex: day 0, time 1 & day 1, time 2
let arrayDaysTimesSingle = []
for(let day=0; day<allSubjectsArr.length; day++) {
for(let time=0; time<allSubjectsArr[day].length; time++) {
for(let times=0; times<allSubjectsArr[day][time].length; times++) {
if(userSubjctsArr[i][j] == allSubjectsArr[day][time][times]) arrayDaysTimesSingle.push([day, time]);
}
}
}
arrayDaysTimesMany.push(arrayDaysTimesSingle);
arrayDaysTimesSingle = [];
}
arrayDaysTimes.push(arrayDaysTimesMany);
arrayDaysTimesMany = [];
}
return arrayDaysTimes;
}
console.log(...arrayDaysTimes)
/* Compare to get possibilities */
// arrayDaysTimes
/* (2) arrayDays times:
[ i
[
[[0,1],[1,0]], "Single SubjectGroup Days&Times"
[[0,1],[1,0]]
],
[
j
[ k في يدي arr [0,1],[1,0]],
[[0,1],[1,0]]
],
[
j
[ k في يدي arr [0,1],[1,0]],
[[0,1],[1,0]]
],
]
*/
// you need to use recursive here
looping(0);
function looping(index) {
for(let i=index; i<arrayDaysTimes.length; i++) {
for(let j=0; j<arrayDaysTimes[i].length; j++) {
for(let k=0; k<arrayDaysTimes[i][j].length; k++) {
if(!isEqualArr(arrayDaysTimes[i][j][k],arrayDaysTimes[i+1][j][k])) {
// push value in final array
} else {
// kill the loop "fine possibilitites"
}
}
looping(i);
// for(let i=0+1; i<arrayDaysTimes.length; i++) {
// for(let j=0; j<arrayDaysTimes[i].length; j++) {
// // you should
// for(let k=0; k<arrayDaysTimes[i][j].length; k++) {
// console.log(arrayDaysTimes[i][j][k])
// }
// }
// }
}
}
}
const isEqualArrs = (arr1, arr2) => {
return JSON.stringify(a) === JSON.stringify(b);
};