This commit is contained in:
Aelita4 2022-12-03 16:57:29 +01:00
parent 84585364cb
commit 11d4023e2d
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
1 changed files with 33 additions and 0 deletions

View File

@ -31,3 +31,36 @@ input.split('\n').forEach(rucksack => {
console.log(prioritySum); console.log(prioritySum);
}); });
console.log();
let countdown = 0, badgesSum = 0;
const group = []
input.split('\n').forEach(rucksack => {
group[countdown++] = rucksack;
if(countdown === 3) {
countdown = 0;
let charFound = false;
for(let i = 0; i < group[0].length; i++) {
for(let j = 0; j < group[1].length; j++) {
for(let k = 0; k < group[2].length; k++) {
if(
group[0].charAt(i) === group[1].charAt(j) &&
group[1].charAt(j) === group[2].charAt(k) &&
group[2].charAt(k) === group[0].charAt(i) &&
!charFound
) {
badgesSum += priorities[group[0].charAt(i)];
charFound = true;
break;
}
}
}
}
console.log(badgesSum);
}
});