math-exercises 1.4.17 → 1.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anagrams.d.ts","sourceRoot":"","sources":["../../../src/exercises/combinatory/anagrams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,YAAY,EAAe,QAAQ,EAAqB,MAAM,0BAA0B,CAAC;AAqEhH,eAAO,MAAM,QAAQ,EAAE,YAWtB,CAAC;
|
|
1
|
+
{"version":3,"file":"anagrams.d.ts","sourceRoot":"","sources":["../../../src/exercises/combinatory/anagrams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,YAAY,EAAe,QAAQ,EAAqB,MAAM,0BAA0B,CAAC;AAqEhH,eAAO,MAAM,QAAQ,EAAE,YAWtB,CAAC;AAkCF,wBAAgB,mBAAmB,IAAI,QAAQ,CAqE9C"}
|
|
@@ -81,12 +81,61 @@ exports.anagrams = {
|
|
|
81
81
|
qcmTimer: 60,
|
|
82
82
|
freeTimer: 60,
|
|
83
83
|
};
|
|
84
|
+
const letters = [
|
|
85
|
+
'a',
|
|
86
|
+
'b',
|
|
87
|
+
'c',
|
|
88
|
+
'd',
|
|
89
|
+
'e',
|
|
90
|
+
'f',
|
|
91
|
+
'g',
|
|
92
|
+
'h',
|
|
93
|
+
'i',
|
|
94
|
+
'j',
|
|
95
|
+
'k',
|
|
96
|
+
'l',
|
|
97
|
+
'm',
|
|
98
|
+
'n',
|
|
99
|
+
'o',
|
|
100
|
+
'p',
|
|
101
|
+
'q',
|
|
102
|
+
'r',
|
|
103
|
+
's',
|
|
104
|
+
't',
|
|
105
|
+
'u',
|
|
106
|
+
'v',
|
|
107
|
+
'w',
|
|
108
|
+
'x',
|
|
109
|
+
'y',
|
|
110
|
+
'z',
|
|
111
|
+
'é',
|
|
112
|
+
'è',
|
|
113
|
+
'à',
|
|
114
|
+
'ç',
|
|
115
|
+
];
|
|
84
116
|
function getAnagramsQuestion() {
|
|
85
117
|
const word = (0, random_1.random)(words);
|
|
86
|
-
const
|
|
118
|
+
const repeats = [];
|
|
119
|
+
const wordLetters = word.split('');
|
|
120
|
+
letters.forEach((letter) => {
|
|
121
|
+
const nbOfRepeats = wordLetters.filter((l) => l === letter).length;
|
|
122
|
+
if (nbOfRepeats > 1)
|
|
123
|
+
repeats.push(nbOfRepeats);
|
|
124
|
+
});
|
|
125
|
+
const getFacto = (n) => {
|
|
126
|
+
if (n === 1)
|
|
127
|
+
return 1;
|
|
128
|
+
return n * getFacto(n - 1);
|
|
129
|
+
};
|
|
130
|
+
const facto = word
|
|
87
131
|
.split('')
|
|
88
132
|
.map((el, index) => index + 1)
|
|
89
133
|
.reduce((acc, curr) => acc * curr, 1);
|
|
134
|
+
let arrangements = 1;
|
|
135
|
+
repeats.forEach((nbOfRepeats) => {
|
|
136
|
+
arrangements *= getFacto(nbOfRepeats);
|
|
137
|
+
});
|
|
138
|
+
const answer = facto / arrangements;
|
|
90
139
|
const getPropositions = (n) => {
|
|
91
140
|
const res = [];
|
|
92
141
|
res.push({
|