-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOJ1759.js
50 lines (38 loc) · 1.28 KB
/
BOJ1759.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
// Solution 1
function getCombinations(array, selectNumber) {
const results = [];
if (selectNumber === 1) {
return array.map((item) => [item]);
}
array.forEach((fixed, index, origin) => {
const rest = origin.slice(index + 1);
const combinations = getCombinations(rest, selectNumber - 1);
const attached = combinations.map((combination) => [fixed, ...combination]);
results.push(...attached);
});
return results;
}
function isVowel(alphabet) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
return vowels.includes(alphabet);
}
function solution(l, c, arr) {
const passwordCombinations = getCombinations(arr, l);
const filteredPasswordCombinations = passwordCombinations
.filter((combination) => {
const vowelCount = combination.filter((alphabet) =>
isVowel(alphabet)
).length;
return vowelCount >= 1 && l - vowelCount >= 2 ? true : false;
})
.map((combination) => combination.join(''));
return filteredPasswordCombinations;
}
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');
const [l, c] = input[0].split(' ').map((num) => Number(num));
const arr = input[1].split(' ').sort();
const result = solution(l, c, arr);
for (const password of result) {
console.log(password);
}