init
This commit is contained in:
commit
f34bb76472
78
Library/index.js
Normal file
78
Library/index.js
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
let inputFile = fs.readFileSync('input.txt', 'utf-8');
|
||||||
|
|
||||||
|
let myArray = inputFile.split('\n').map((line) => line.split(' '));
|
||||||
|
|
||||||
|
const TOTAL_SIGNUP_TIME = parseInt(myArray[0][2]);
|
||||||
|
|
||||||
|
let libraryScores = [];
|
||||||
|
let libraryBooksScore = [];
|
||||||
|
let maxLibraries = [];
|
||||||
|
|
||||||
|
for (let i = 2; i < myArray.length; i += 2) {
|
||||||
|
const libraryBooks = myArray[i + 1];
|
||||||
|
|
||||||
|
const daysToScan = TOTAL_SIGNUP_TIME - parseInt(myArray[i][1]);
|
||||||
|
const maxBooks = parseInt(myArray[i][2]) * daysToScan;
|
||||||
|
|
||||||
|
let libraryBook = [];
|
||||||
|
|
||||||
|
const libraryScore = libraryBooks
|
||||||
|
.map((bookIndex) => parseInt(myArray[1][bookIndex]))
|
||||||
|
.sort()
|
||||||
|
.reverse()
|
||||||
|
.slice(0, maxBooks)
|
||||||
|
.map((bookValue) => {
|
||||||
|
myArray[1].forEach((v, i) => {
|
||||||
|
if (
|
||||||
|
v.toString() === bookValue.toString() &&
|
||||||
|
libraryBooks.includes(i.toString())
|
||||||
|
) {
|
||||||
|
libraryBook.push(i);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return bookValue;
|
||||||
|
})
|
||||||
|
.reduce((result, item) => result + item, 0);
|
||||||
|
|
||||||
|
libraryScores.push(libraryScore);
|
||||||
|
libraryBooksScore.push(libraryBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
let copyLibraryScores = [...libraryScores];
|
||||||
|
copyLibraryScores = copyLibraryScores.sort().reverse();
|
||||||
|
copyLibraryScores.forEach((score) => {
|
||||||
|
libraryScores.forEach((s, libraryIndex) => {
|
||||||
|
if (s.toString() === score.toString()) {
|
||||||
|
maxLibraries.push(libraryIndex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
let totalNumberofLibraries = 0;
|
||||||
|
let totalSignupTime = TOTAL_SIGNUP_TIME;
|
||||||
|
|
||||||
|
while (totalSignupTime > 0 && totalNumberofLibraries < maxLibraries.length) {
|
||||||
|
totalSignupTime -= parseInt(
|
||||||
|
myArray[maxLibraries[totalNumberofLibraries] * 2 + 2][1]
|
||||||
|
);
|
||||||
|
totalNumberofLibraries++;
|
||||||
|
}
|
||||||
|
|
||||||
|
let booksToSendScanning = [];
|
||||||
|
let totalSignupYet = TOTAL_SIGNUP_TIME;
|
||||||
|
for (let j = 0; j < maxLibraries.length; j++) {
|
||||||
|
totalSignupYet -= myArray[maxLibraries[j] * 2 + 2][1];
|
||||||
|
const maxCurrentBooks =
|
||||||
|
(TOTAL_SIGNUP_TIME - totalSignupYet) * myArray[maxLibraries[j] * 2 + 2][2];
|
||||||
|
booksToSendScanning.push([
|
||||||
|
...libraryBooksScore[maxLibraries[j]].slice(0, maxCurrentBooks),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`${totalNumberofLibraries}`);
|
||||||
|
for (let k = 0; k < booksToSendScanning.length; k++) {
|
||||||
|
console.log(`${maxLibraries[k]} ${booksToSendScanning[k].length}`);
|
||||||
|
console.log(`${booksToSendScanning[k].join(' ')}`);
|
||||||
|
}
|
6
Library/input.txt
Normal file
6
Library/input.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
6 2 7
|
||||||
|
1 2 3 6 5 4
|
||||||
|
5 2 2
|
||||||
|
0 1 2 3 4
|
||||||
|
4 3 1
|
||||||
|
3 2 5 0
|
5
Library/result.txt
Normal file
5
Library/result.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
2
|
||||||
|
0 5
|
||||||
|
3 4 2 1 0
|
||||||
|
1 1
|
||||||
|
5
|
132
Library/solution.js
Normal file
132
Library/solution.js
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const file = fs.readFileSync('input.txt', 'utf-8');
|
||||||
|
const result = file.split('\n').map((item) => item.split(' '));
|
||||||
|
|
||||||
|
const readyLibraries = [];
|
||||||
|
|
||||||
|
const set = {
|
||||||
|
bookNumber: parseInt(result[0][0]),
|
||||||
|
deadline: parseInt(result[0][2]),
|
||||||
|
booksScore: [...result[1].map((it) => parseInt(it, 10))],
|
||||||
|
libraries: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Loop on all libraries
|
||||||
|
for (let i = 0; i < result[0][1]; i++) {
|
||||||
|
const firstRow = result[i * 2 + 2];
|
||||||
|
const secondRow = result[i * 2 + 3];
|
||||||
|
|
||||||
|
set.libraries.push({
|
||||||
|
daysToSignUp: parseInt(firstRow[1]),
|
||||||
|
scanPerDay: parseInt(firstRow[2]),
|
||||||
|
// Sort & insert list of books in descending order of highest value per lib
|
||||||
|
books: [
|
||||||
|
...secondRow
|
||||||
|
.map((it) => parseInt(it, 10))
|
||||||
|
.sort((a, b) => set.booksScore[b] - set.booksScore[a]),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let signupLibrary = null;
|
||||||
|
|
||||||
|
for (let j = 0; j < set.deadline; j++) {
|
||||||
|
if (!signupLibrary) {
|
||||||
|
signupLibrary = findLibraryToSetup(j);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (signupLibrary) {
|
||||||
|
signupLibrary.daysToSignUp--;
|
||||||
|
|
||||||
|
if (signupLibrary.daysToSignUp === 0) {
|
||||||
|
// Keep only max number of books possible
|
||||||
|
const scannedBooks = set.libraries[signupLibrary.id].books.slice(
|
||||||
|
0,
|
||||||
|
signupLibrary.booksCount
|
||||||
|
);
|
||||||
|
|
||||||
|
readyLibraries.push({
|
||||||
|
id: signupLibrary.id,
|
||||||
|
books: scannedBooks,
|
||||||
|
});
|
||||||
|
|
||||||
|
set.libraries[signupLibrary.id] = undefined;
|
||||||
|
signupLibrary = null;
|
||||||
|
removeDuplicates(scannedBooks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function findLibraryToSetup(currentDay) {
|
||||||
|
const availableLibraries = set.libraries
|
||||||
|
.map((library, index) =>
|
||||||
|
library !== undefined
|
||||||
|
? {
|
||||||
|
id: index,
|
||||||
|
value: 0,
|
||||||
|
daysToSignUp: library.daysToSignUp,
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
)
|
||||||
|
.filter((item) => item !== undefined);
|
||||||
|
|
||||||
|
availableLibraries.forEach((library) => {
|
||||||
|
const activeDays = set.deadline - currentDay - library.daysToSignUp;
|
||||||
|
const trueLibrary = set.libraries[library.id];
|
||||||
|
|
||||||
|
// Find minimum of max books per day * days available OR amount of books in lib
|
||||||
|
const scannedBooks = Math.min(
|
||||||
|
activeDays * trueLibrary.scanPerDay,
|
||||||
|
trueLibrary.books.length
|
||||||
|
);
|
||||||
|
|
||||||
|
library.booksCount = scannedBooks;
|
||||||
|
trueLibrary.books.slice(0, scannedBooks).forEach((id) => {
|
||||||
|
library.value += set.booksScore[id];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get a kind of score ratio
|
||||||
|
library.value /= library.daysToSignUp;
|
||||||
|
});
|
||||||
|
|
||||||
|
const sorted = availableLibraries.sort((a, b) => {
|
||||||
|
// If equal value, put the one with the highest value first
|
||||||
|
if (b.value === a.value) {
|
||||||
|
return b.daysToSignUp - a.daysToSignUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return b.value - a.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
return sorted[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeDuplicates(booksToRemove) {
|
||||||
|
set.libraries.forEach((library) => {
|
||||||
|
if (library) {
|
||||||
|
library.books = library.books.filter(
|
||||||
|
(book) => !booksToRemove.some((book1) => book1 === book)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let results = 0;
|
||||||
|
|
||||||
|
readyLibraries.forEach((lib) => {
|
||||||
|
lib.books.forEach((book) => {
|
||||||
|
results += set.booksScore[book];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`score: ${results}`);
|
||||||
|
|
||||||
|
const finalResult = [readyLibraries.length];
|
||||||
|
readyLibraries.forEach((library) => {
|
||||||
|
finalResult.push(`${library.id} ${library.books.length}`);
|
||||||
|
finalResult.push(library.books.join(' '));
|
||||||
|
});
|
||||||
|
|
||||||
|
// fs.writeFileSync(files[process.env.FILE].output, finalResult.join("\n"))
|
||||||
|
fs.writeFileSync('result.txt', finalResult.join('\n'));
|
6
Pizza/data/a_example
Normal file
6
Pizza/data/a_example
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
5 1 2 1
|
||||||
|
3 onion pepper olive
|
||||||
|
3 mushroom tomato basil
|
||||||
|
3 chicken mushroom pepper
|
||||||
|
3 tomato mushroom basil
|
||||||
|
2 chicken basil
|
501
Pizza/data/b_little_bit_of_everything.in
Normal file
501
Pizza/data/b_little_bit_of_everything.in
Normal file
@ -0,0 +1,501 @@
|
|||||||
|
500 65 60 60
|
||||||
|
5 mushrooms onions neapolitan-crust emmental-cheese cheddar
|
||||||
|
8 mushrooms tomatoes onions pineapple neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
1 basil
|
||||||
|
3 tomatoes emmental-cheese mozzarella
|
||||||
|
1 pineapple
|
||||||
|
4 onions neapolitan-crust emmental-cheese mozzarella
|
||||||
|
3 mushrooms basil mozzarella
|
||||||
|
7 mushrooms onions pineapple ham neapolitan-crust mozzarella cheddar
|
||||||
|
3 pineapple ham neapolitan-crust
|
||||||
|
1 ham
|
||||||
|
3 tomatoes basil mozzarella
|
||||||
|
6 mushrooms tomatoes ham neapolitan-crust mozzarella cheddar
|
||||||
|
9 mushrooms tomatoes onions ham basil neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
3 mushrooms tomatoes mozzarella
|
||||||
|
8 mushrooms onions pineapple neapolitan-crust ham basil emmental-cheese cheddar
|
||||||
|
4 mushrooms emmental-cheese mozzarella cheddar
|
||||||
|
2 basil cheddar
|
||||||
|
7 tomatoes pineapple neapolitan-crust basil emmental-cheese mozzarella cheddar
|
||||||
|
3 ham neapolitan-crust mozzarella
|
||||||
|
4 onions ham basil cheddar
|
||||||
|
4 pineapple ham emmental-cheese mozzarella
|
||||||
|
8 mushrooms tomatoes onions pineapple basil neapolitan-crust mozzarella cheddar
|
||||||
|
2 ham neapolitan-crust
|
||||||
|
3 neapolitan-crust emmental-cheese cheddar
|
||||||
|
3 mushrooms basil neapolitan-crust
|
||||||
|
2 pineapple mozzarella
|
||||||
|
2 mushrooms tomatoes
|
||||||
|
2 emmental-cheese mozzarella
|
||||||
|
10 mushrooms tomatoes onions pineapple basil ham neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
2 mushrooms ham
|
||||||
|
1 mozzarella
|
||||||
|
3 onions basil cheddar
|
||||||
|
2 onions cheddar
|
||||||
|
9 mushrooms tomatoes onions pineapple neapolitan-crust basil emmental-cheese mozzarella cheddar
|
||||||
|
4 mushrooms tomatoes basil emmental-cheese
|
||||||
|
10 mushrooms tomatoes onions pineapple ham basil neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
2 onions neapolitan-crust
|
||||||
|
1 emmental-cheese
|
||||||
|
5 mushrooms tomatoes onions basil cheddar
|
||||||
|
1 onions
|
||||||
|
2 mushrooms emmental-cheese
|
||||||
|
2 onions mozzarella
|
||||||
|
1 ham
|
||||||
|
1 ham
|
||||||
|
2 mushrooms onions
|
||||||
|
2 tomatoes cheddar
|
||||||
|
2 pineapple neapolitan-crust
|
||||||
|
9 mushrooms tomatoes onions neapolitan-crust basil ham emmental-cheese mozzarella cheddar
|
||||||
|
5 mushrooms pineapple ham basil emmental-cheese
|
||||||
|
1 mozzarella
|
||||||
|
2 tomatoes cheddar
|
||||||
|
1 basil
|
||||||
|
5 mushrooms onions ham neapolitan-crust mozzarella
|
||||||
|
1 ham
|
||||||
|
2 onions neapolitan-crust
|
||||||
|
3 mushrooms basil emmental-cheese
|
||||||
|
2 mozzarella cheddar
|
||||||
|
1 emmental-cheese
|
||||||
|
1 ham
|
||||||
|
2 emmental-cheese mozzarella
|
||||||
|
4 mushrooms tomatoes basil emmental-cheese
|
||||||
|
4 mushrooms basil emmental-cheese cheddar
|
||||||
|
1 cheddar
|
||||||
|
1 basil
|
||||||
|
6 tomatoes onions pineapple basil mozzarella cheddar
|
||||||
|
3 neapolitan-crust emmental-cheese cheddar
|
||||||
|
2 neapolitan-crust emmental-cheese
|
||||||
|
1 cheddar
|
||||||
|
1 basil
|
||||||
|
2 mozzarella cheddar
|
||||||
|
2 tomatoes ham
|
||||||
|
3 onions neapolitan-crust mozzarella
|
||||||
|
6 mushrooms tomatoes basil ham emmental-cheese cheddar
|
||||||
|
6 tomatoes ham neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
1 mushrooms
|
||||||
|
1 ham
|
||||||
|
2 mushrooms emmental-cheese
|
||||||
|
1 pineapple
|
||||||
|
2 mushrooms onions
|
||||||
|
2 onions mozzarella
|
||||||
|
2 pineapple cheddar
|
||||||
|
2 emmental-cheese cheddar
|
||||||
|
1 ham
|
||||||
|
1 basil
|
||||||
|
1 basil
|
||||||
|
1 onions
|
||||||
|
7 mushrooms tomatoes onions pineapple neapolitan-crust basil ham
|
||||||
|
1 emmental-cheese
|
||||||
|
1 cheddar
|
||||||
|
3 mushrooms neapolitan-crust ham
|
||||||
|
3 basil mozzarella cheddar
|
||||||
|
3 mushrooms tomatoes emmental-cheese
|
||||||
|
2 mushrooms neapolitan-crust
|
||||||
|
10 mushrooms tomatoes onions pineapple neapolitan-crust basil ham emmental-cheese mozzarella cheddar
|
||||||
|
1 tomatoes
|
||||||
|
2 tomatoes onions
|
||||||
|
1 basil
|
||||||
|
10 mushrooms tomatoes onions pineapple neapolitan-crust ham basil emmental-cheese mozzarella cheddar
|
||||||
|
1 cheddar
|
||||||
|
3 onions neapolitan-crust basil
|
||||||
|
2 ham cheddar
|
||||||
|
2 tomatoes neapolitan-crust
|
||||||
|
1 neapolitan-crust
|
||||||
|
1 tomatoes
|
||||||
|
2 pineapple neapolitan-crust
|
||||||
|
3 neapolitan-crust basil emmental-cheese
|
||||||
|
2 onions basil
|
||||||
|
2 basil emmental-cheese
|
||||||
|
5 mushrooms tomatoes basil neapolitan-crust emmental-cheese
|
||||||
|
2 basil emmental-cheese
|
||||||
|
1 tomatoes
|
||||||
|
5 mushrooms pineapple basil ham cheddar
|
||||||
|
2 ham basil
|
||||||
|
5 mushrooms tomatoes pineapple basil ham
|
||||||
|
2 tomatoes pineapple
|
||||||
|
2 onions mozzarella
|
||||||
|
2 pineapple mozzarella
|
||||||
|
3 onions emmental-cheese cheddar
|
||||||
|
1 pineapple
|
||||||
|
2 ham cheddar
|
||||||
|
6 pineapple ham neapolitan-crust basil mozzarella cheddar
|
||||||
|
3 pineapple basil ham
|
||||||
|
1 ham
|
||||||
|
3 onions pineapple basil
|
||||||
|
2 onions emmental-cheese
|
||||||
|
1 cheddar
|
||||||
|
1 onions
|
||||||
|
1 ham
|
||||||
|
2 pineapple basil
|
||||||
|
2 neapolitan-crust emmental-cheese
|
||||||
|
1 pineapple
|
||||||
|
1 pineapple
|
||||||
|
2 ham cheddar
|
||||||
|
1 mozzarella
|
||||||
|
1 neapolitan-crust
|
||||||
|
1 pineapple
|
||||||
|
2 onions pineapple
|
||||||
|
1 cheddar
|
||||||
|
2 pineapple basil
|
||||||
|
3 mushrooms onions emmental-cheese
|
||||||
|
1 neapolitan-crust
|
||||||
|
6 onions pineapple basil neapolitan-crust emmental-cheese mozzarella
|
||||||
|
1 mushrooms
|
||||||
|
1 emmental-cheese
|
||||||
|
2 mushrooms basil
|
||||||
|
1 mozzarella
|
||||||
|
1 tomatoes
|
||||||
|
4 ham neapolitan-crust basil cheddar
|
||||||
|
2 tomatoes pineapple
|
||||||
|
3 tomatoes onions ham
|
||||||
|
1 basil
|
||||||
|
2 tomatoes ham
|
||||||
|
2 ham mozzarella
|
||||||
|
2 mushrooms cheddar
|
||||||
|
7 mushrooms tomatoes onions pineapple neapolitan-crust emmental-cheese mozzarella
|
||||||
|
5 pineapple basil neapolitan-crust emmental-cheese mozzarella
|
||||||
|
6 tomatoes onions neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
1 neapolitan-crust
|
||||||
|
6 tomatoes onions neapolitan-crust ham emmental-cheese cheddar
|
||||||
|
3 pineapple mozzarella cheddar
|
||||||
|
2 ham emmental-cheese
|
||||||
|
1 pineapple
|
||||||
|
3 mushrooms tomatoes neapolitan-crust
|
||||||
|
3 pineapple ham neapolitan-crust
|
||||||
|
2 onions emmental-cheese
|
||||||
|
9 mushrooms tomatoes onions pineapple neapolitan-crust basil emmental-cheese mozzarella cheddar
|
||||||
|
5 mushrooms tomatoes onions ham cheddar
|
||||||
|
1 neapolitan-crust
|
||||||
|
1 emmental-cheese
|
||||||
|
1 onions
|
||||||
|
6 mushrooms tomatoes basil neapolitan-crust mozzarella cheddar
|
||||||
|
1 basil
|
||||||
|
2 neapolitan-crust cheddar
|
||||||
|
1 mushrooms
|
||||||
|
2 ham mozzarella
|
||||||
|
4 tomatoes onions neapolitan-crust emmental-cheese
|
||||||
|
1 neapolitan-crust
|
||||||
|
3 onions pineapple ham
|
||||||
|
1 emmental-cheese
|
||||||
|
1 mozzarella
|
||||||
|
3 tomatoes pineapple ham
|
||||||
|
4 tomatoes ham neapolitan-crust emmental-cheese
|
||||||
|
6 mushrooms tomatoes onions pineapple emmental-cheese mozzarella
|
||||||
|
1 pineapple
|
||||||
|
1 emmental-cheese
|
||||||
|
2 onions cheddar
|
||||||
|
2 onions neapolitan-crust
|
||||||
|
4 mushrooms basil emmental-cheese mozzarella
|
||||||
|
3 neapolitan-crust basil mozzarella
|
||||||
|
7 tomatoes onions pineapple basil ham mozzarella cheddar
|
||||||
|
10 mushrooms tomatoes onions pineapple ham neapolitan-crust basil emmental-cheese mozzarella cheddar
|
||||||
|
1 basil
|
||||||
|
3 mushrooms onions basil
|
||||||
|
4 tomatoes pineapple neapolitan-crust mozzarella
|
||||||
|
1 basil
|
||||||
|
2 neapolitan-crust basil
|
||||||
|
10 mushrooms tomatoes onions pineapple basil ham neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
10 mushrooms tomatoes onions pineapple ham neapolitan-crust basil emmental-cheese mozzarella cheddar
|
||||||
|
2 onions ham
|
||||||
|
4 tomatoes basil emmental-cheese cheddar
|
||||||
|
2 basil mozzarella
|
||||||
|
3 tomatoes neapolitan-crust ham
|
||||||
|
1 mushrooms
|
||||||
|
3 mushrooms pineapple neapolitan-crust
|
||||||
|
2 emmental-cheese cheddar
|
||||||
|
1 basil
|
||||||
|
1 cheddar
|
||||||
|
2 basil mozzarella
|
||||||
|
4 mushrooms pineapple basil emmental-cheese
|
||||||
|
1 cheddar
|
||||||
|
5 pineapple basil emmental-cheese mozzarella cheddar
|
||||||
|
1 cheddar
|
||||||
|
7 mushrooms tomatoes ham neapolitan-crust basil mozzarella cheddar
|
||||||
|
6 mushrooms pineapple basil ham neapolitan-crust mozzarella
|
||||||
|
3 tomatoes onions neapolitan-crust
|
||||||
|
1 neapolitan-crust
|
||||||
|
1 mozzarella
|
||||||
|
2 onions neapolitan-crust
|
||||||
|
3 onions pineapple mozzarella
|
||||||
|
4 mushrooms tomatoes onions emmental-cheese
|
||||||
|
1 mozzarella
|
||||||
|
5 tomatoes pineapple basil emmental-cheese cheddar
|
||||||
|
1 ham
|
||||||
|
1 ham
|
||||||
|
1 tomatoes
|
||||||
|
3 mushrooms onions ham
|
||||||
|
2 mushrooms basil
|
||||||
|
1 ham
|
||||||
|
1 pineapple
|
||||||
|
1 tomatoes
|
||||||
|
3 mushrooms onions basil
|
||||||
|
4 mushrooms pineapple basil ham
|
||||||
|
1 pineapple
|
||||||
|
2 tomatoes ham
|
||||||
|
5 tomatoes pineapple neapolitan-crust emmental-cheese cheddar
|
||||||
|
3 tomatoes emmental-cheese cheddar
|
||||||
|
4 tomatoes ham mozzarella cheddar
|
||||||
|
2 onions basil
|
||||||
|
1 onions
|
||||||
|
1 mozzarella
|
||||||
|
4 tomatoes onions pineapple neapolitan-crust
|
||||||
|
1 mushrooms
|
||||||
|
3 tomatoes neapolitan-crust emmental-cheese
|
||||||
|
1 mozzarella
|
||||||
|
2 mushrooms ham
|
||||||
|
2 pineapple basil
|
||||||
|
1 basil
|
||||||
|
2 emmental-cheese cheddar
|
||||||
|
1 ham
|
||||||
|
4 mushrooms pineapple basil emmental-cheese
|
||||||
|
1 tomatoes
|
||||||
|
2 emmental-cheese mozzarella
|
||||||
|
10 mushrooms tomatoes onions pineapple neapolitan-crust ham basil emmental-cheese mozzarella cheddar
|
||||||
|
1 emmental-cheese
|
||||||
|
2 mushrooms tomatoes
|
||||||
|
1 basil
|
||||||
|
8 mushrooms tomatoes pineapple ham neapolitan-crust basil emmental-cheese mozzarella
|
||||||
|
1 onions
|
||||||
|
4 mushrooms ham basil neapolitan-crust
|
||||||
|
2 mozzarella cheddar
|
||||||
|
1 neapolitan-crust
|
||||||
|
5 mushrooms tomatoes pineapple neapolitan-crust ham
|
||||||
|
1 onions
|
||||||
|
3 mushrooms neapolitan-crust cheddar
|
||||||
|
5 onions pineapple basil ham mozzarella
|
||||||
|
1 mushrooms
|
||||||
|
6 mushrooms onions pineapple ham mozzarella cheddar
|
||||||
|
2 tomatoes basil
|
||||||
|
3 mushrooms neapolitan-crust mozzarella
|
||||||
|
2 neapolitan-crust emmental-cheese
|
||||||
|
1 pineapple
|
||||||
|
4 mushrooms tomatoes ham mozzarella
|
||||||
|
1 tomatoes
|
||||||
|
4 tomatoes pineapple emmental-cheese cheddar
|
||||||
|
2 pineapple cheddar
|
||||||
|
1 pineapple
|
||||||
|
3 pineapple ham neapolitan-crust
|
||||||
|
4 mushrooms pineapple neapolitan-crust ham
|
||||||
|
3 onions neapolitan-crust basil
|
||||||
|
8 mushrooms tomatoes pineapple ham basil emmental-cheese mozzarella cheddar
|
||||||
|
2 mushrooms onions
|
||||||
|
1 pineapple
|
||||||
|
2 pineapple cheddar
|
||||||
|
3 mushrooms tomatoes emmental-cheese
|
||||||
|
2 basil mozzarella
|
||||||
|
2 mushrooms onions
|
||||||
|
10 mushrooms tomatoes onions pineapple ham neapolitan-crust basil emmental-cheese mozzarella cheddar
|
||||||
|
1 basil
|
||||||
|
4 mushrooms ham emmental-cheese mozzarella
|
||||||
|
2 mozzarella cheddar
|
||||||
|
1 mozzarella
|
||||||
|
1 cheddar
|
||||||
|
4 mushrooms tomatoes ham cheddar
|
||||||
|
1 emmental-cheese
|
||||||
|
3 pineapple neapolitan-crust emmental-cheese
|
||||||
|
2 mushrooms mozzarella
|
||||||
|
1 cheddar
|
||||||
|
1 mushrooms
|
||||||
|
5 mushrooms pineapple neapolitan-crust ham mozzarella
|
||||||
|
8 mushrooms tomatoes onions pineapple neapolitan-crust ham basil emmental-cheese
|
||||||
|
9 mushrooms onions pineapple ham neapolitan-crust basil emmental-cheese mozzarella cheddar
|
||||||
|
6 mushrooms tomatoes pineapple neapolitan-crust basil emmental-cheese
|
||||||
|
3 mushrooms mozzarella cheddar
|
||||||
|
1 emmental-cheese
|
||||||
|
2 tomatoes emmental-cheese
|
||||||
|
1 mushrooms
|
||||||
|
8 mushrooms tomatoes onions pineapple neapolitan-crust ham basil emmental-cheese
|
||||||
|
2 tomatoes onions
|
||||||
|
1 cheddar
|
||||||
|
1 mushrooms
|
||||||
|
5 mushrooms tomatoes basil neapolitan-crust mozzarella
|
||||||
|
4 mushrooms tomatoes basil neapolitan-crust
|
||||||
|
1 mushrooms
|
||||||
|
1 pineapple
|
||||||
|
1 onions
|
||||||
|
8 tomatoes onions pineapple neapolitan-crust ham emmental-cheese mozzarella cheddar
|
||||||
|
1 pineapple
|
||||||
|
1 emmental-cheese
|
||||||
|
1 emmental-cheese
|
||||||
|
6 mushrooms onions basil neapolitan-crust emmental-cheese mozzarella
|
||||||
|
4 onions ham basil cheddar
|
||||||
|
1 mozzarella
|
||||||
|
8 tomatoes onions basil ham neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
1 onions
|
||||||
|
4 pineapple ham neapolitan-crust mozzarella
|
||||||
|
2 ham cheddar
|
||||||
|
9 mushrooms tomatoes onions pineapple ham basil neapolitan-crust emmental-cheese mozzarella
|
||||||
|
1 tomatoes
|
||||||
|
3 mushrooms ham mozzarella
|
||||||
|
5 tomatoes pineapple ham mozzarella cheddar
|
||||||
|
8 tomatoes onions pineapple basil neapolitan-crust ham emmental-cheese cheddar
|
||||||
|
1 neapolitan-crust
|
||||||
|
2 mushrooms neapolitan-crust
|
||||||
|
10 mushrooms tomatoes onions pineapple basil ham neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
7 mushrooms onions pineapple ham basil emmental-cheese cheddar
|
||||||
|
1 onions
|
||||||
|
3 mushrooms neapolitan-crust mozzarella
|
||||||
|
6 onions neapolitan-crust ham basil emmental-cheese mozzarella
|
||||||
|
1 emmental-cheese
|
||||||
|
2 onions basil
|
||||||
|
1 pineapple
|
||||||
|
2 basil neapolitan-crust
|
||||||
|
1 mushrooms
|
||||||
|
1 onions
|
||||||
|
1 emmental-cheese
|
||||||
|
3 pineapple basil cheddar
|
||||||
|
1 emmental-cheese
|
||||||
|
2 pineapple neapolitan-crust
|
||||||
|
3 mushrooms pineapple basil
|
||||||
|
1 mozzarella
|
||||||
|
5 mushrooms tomatoes pineapple mozzarella cheddar
|
||||||
|
3 mushrooms tomatoes ham
|
||||||
|
7 mushrooms tomatoes onions basil neapolitan-crust mozzarella cheddar
|
||||||
|
3 emmental-cheese mozzarella cheddar
|
||||||
|
1 emmental-cheese
|
||||||
|
1 pineapple
|
||||||
|
4 mushrooms onions basil cheddar
|
||||||
|
1 basil
|
||||||
|
7 onions pineapple neapolitan-crust ham emmental-cheese mozzarella cheddar
|
||||||
|
2 tomatoes mozzarella
|
||||||
|
4 onions basil ham neapolitan-crust
|
||||||
|
2 tomatoes cheddar
|
||||||
|
3 pineapple neapolitan-crust mozzarella
|
||||||
|
2 mushrooms cheddar
|
||||||
|
3 pineapple ham neapolitan-crust
|
||||||
|
2 tomatoes mozzarella
|
||||||
|
1 ham
|
||||||
|
4 mushrooms pineapple basil cheddar
|
||||||
|
1 neapolitan-crust
|
||||||
|
10 mushrooms tomatoes onions pineapple ham basil neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
1 basil
|
||||||
|
5 mushrooms ham neapolitan-crust emmental-cheese cheddar
|
||||||
|
2 basil neapolitan-crust
|
||||||
|
2 mushrooms emmental-cheese
|
||||||
|
1 onions
|
||||||
|
3 mushrooms tomatoes neapolitan-crust
|
||||||
|
5 tomatoes onions ham basil neapolitan-crust
|
||||||
|
2 tomatoes mozzarella
|
||||||
|
2 mushrooms basil
|
||||||
|
2 tomatoes ham
|
||||||
|
1 tomatoes
|
||||||
|
1 mushrooms
|
||||||
|
1 mushrooms
|
||||||
|
1 pineapple
|
||||||
|
3 tomatoes neapolitan-crust ham
|
||||||
|
4 tomatoes pineapple basil cheddar
|
||||||
|
1 cheddar
|
||||||
|
4 pineapple ham neapolitan-crust emmental-cheese
|
||||||
|
3 mushrooms onions basil
|
||||||
|
1 emmental-cheese
|
||||||
|
2 tomatoes mozzarella
|
||||||
|
3 onions ham neapolitan-crust
|
||||||
|
3 mushrooms ham mozzarella
|
||||||
|
1 cheddar
|
||||||
|
3 onions emmental-cheese cheddar
|
||||||
|
2 onions ham
|
||||||
|
4 tomatoes emmental-cheese mozzarella cheddar
|
||||||
|
3 pineapple neapolitan-crust emmental-cheese
|
||||||
|
1 mozzarella
|
||||||
|
3 neapolitan-crust basil ham
|
||||||
|
3 neapolitan-crust emmental-cheese cheddar
|
||||||
|
2 emmental-cheese mozzarella
|
||||||
|
1 tomatoes
|
||||||
|
3 basil neapolitan-crust mozzarella
|
||||||
|
1 cheddar
|
||||||
|
4 onions basil emmental-cheese cheddar
|
||||||
|
1 ham
|
||||||
|
3 mushrooms tomatoes pineapple
|
||||||
|
1 neapolitan-crust
|
||||||
|
4 tomatoes ham basil cheddar
|
||||||
|
6 tomatoes onions basil neapolitan-crust emmental-cheese cheddar
|
||||||
|
2 onions neapolitan-crust
|
||||||
|
3 onions pineapple ham
|
||||||
|
1 mozzarella
|
||||||
|
7 onions pineapple neapolitan-crust ham emmental-cheese mozzarella cheddar
|
||||||
|
1 neapolitan-crust
|
||||||
|
1 emmental-cheese
|
||||||
|
1 neapolitan-crust
|
||||||
|
1 pineapple
|
||||||
|
4 tomatoes basil ham neapolitan-crust
|
||||||
|
10 mushrooms tomatoes onions pineapple neapolitan-crust basil ham emmental-cheese mozzarella cheddar
|
||||||
|
8 mushrooms tomatoes onions ham basil emmental-cheese mozzarella cheddar
|
||||||
|
3 tomatoes ham mozzarella
|
||||||
|
10 mushrooms tomatoes onions pineapple ham neapolitan-crust basil emmental-cheese mozzarella cheddar
|
||||||
|
3 onions ham basil
|
||||||
|
2 mushrooms tomatoes
|
||||||
|
1 mushrooms
|
||||||
|
3 tomatoes ham neapolitan-crust
|
||||||
|
1 pineapple
|
||||||
|
3 onions pineapple ham
|
||||||
|
4 mushrooms ham mozzarella cheddar
|
||||||
|
3 onions ham neapolitan-crust
|
||||||
|
2 tomatoes neapolitan-crust
|
||||||
|
4 pineapple neapolitan-crust ham cheddar
|
||||||
|
5 tomatoes ham basil emmental-cheese mozzarella
|
||||||
|
1 ham
|
||||||
|
1 tomatoes
|
||||||
|
3 onions neapolitan-crust emmental-cheese
|
||||||
|
3 onions neapolitan-crust ham
|
||||||
|
4 mushrooms tomatoes onions neapolitan-crust
|
||||||
|
1 mozzarella
|
||||||
|
10 mushrooms tomatoes onions pineapple ham basil neapolitan-crust emmental-cheese mozzarella cheddar
|
||||||
|
3 tomatoes onions ham
|
||||||
|
6 mushrooms ham basil emmental-cheese mozzarella cheddar
|
||||||
|
3 tomatoes onions ham
|
||||||
|
4 basil emmental-cheese mozzarella cheddar
|
||||||
|
2 mushrooms tomatoes
|
||||||
|
3 tomatoes neapolitan-crust ham
|
||||||
|
5 mushrooms tomatoes ham basil emmental-cheese
|
||||||
|
3 onions basil cheddar
|
||||||
|
2 tomatoes basil
|
||||||
|
5 mushrooms tomatoes pineapple mozzarella cheddar
|
||||||
|
5 mushrooms pineapple emmental-cheese mozzarella cheddar
|
||||||
|
2 mushrooms emmental-cheese
|
||||||
|
8 mushrooms tomatoes onions neapolitan-crust basil ham mozzarella cheddar
|
||||||
|
4 tomatoes pineapple basil emmental-cheese
|
||||||
|
1 ham
|
||||||
|
1 neapolitan-crust
|
||||||
|
1 mushrooms
|
||||||
|
3 tomatoes ham mozzarella
|
||||||
|
2 mushrooms onions
|
||||||
|
2 tomatoes cheddar
|
||||||
|
6 tomatoes pineapple basil neapolitan-crust emmental-cheese cheddar
|
||||||
|
5 tomatoes onions pineapple emmental-cheese cheddar
|
||||||
|
1 tomatoes
|
||||||
|
1 onions
|
||||||
|
1 mozzarella
|
||||||
|
3 mushrooms tomatoes emmental-cheese
|
||||||
|
2 pineapple emmental-cheese
|
||||||
|
1 pineapple
|
||||||
|
1 onions
|
||||||
|
1 emmental-cheese
|
||||||
|
3 onions ham mozzarella
|
||||||
|
4 tomatoes onions neapolitan-crust basil
|
||||||
|
3 tomatoes pineapple emmental-cheese
|
||||||
|
5 mushrooms tomatoes basil ham cheddar
|
||||||
|
1 pineapple
|
||||||
|
1 mushrooms
|
||||||
|
1 cheddar
|
||||||
|
1 tomatoes
|
||||||
|
1 tomatoes
|
||||||
|
1 mushrooms
|
||||||
|
9 mushrooms tomatoes onions pineapple basil neapolitan-crust ham mozzarella cheddar
|
||||||
|
1 ham
|
||||||
|
6 mushrooms tomatoes pineapple ham basil mozzarella
|
||||||
|
1 neapolitan-crust
|
||||||
|
5 tomatoes onions neapolitan-crust emmental-cheese mozzarella
|
||||||
|
1 cheddar
|
||||||
|
1 basil
|
||||||
|
1 ham
|
||||||
|
2 pineapple ham
|
||||||
|
1 cheddar
|
||||||
|
7 onions pineapple basil ham emmental-cheese mozzarella cheddar
|
||||||
|
1 mushrooms
|
||||||
|
2 tomatoes basil
|
||||||
|
6 mushrooms pineapple ham basil mozzarella cheddar
|
||||||
|
1 onions
|
||||||
|
3 ham basil emmental-cheese
|
||||||
|
4 mushrooms emmental-cheese mozzarella cheddar
|
||||||
|
4 tomatoes pineapple neapolitan-crust basil
|
10001
Pizza/data/c_many_ingredients.in
Normal file
10001
Pizza/data/c_many_ingredients.in
Normal file
File diff suppressed because it is too large
Load Diff
100001
Pizza/data/d_many_pizzas.in
Normal file
100001
Pizza/data/d_many_pizzas.in
Normal file
File diff suppressed because it is too large
Load Diff
100001
Pizza/data/e_many_teams.in
Normal file
100001
Pizza/data/e_many_teams.in
Normal file
File diff suppressed because it is too large
Load Diff
281
Pizza/index.js
Normal file
281
Pizza/index.js
Normal file
@ -0,0 +1,281 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const file_a = fs.readFileSync('data/a_example', 'utf-8');
|
||||||
|
const file_b = fs.readFileSync('data/b_little_bit_of_everything.in', 'utf-8');
|
||||||
|
const file_c = fs.readFileSync('data/c_many_ingredients.in', 'utf-8');
|
||||||
|
const file_d = fs.readFileSync('data/d_many_pizzas.in', 'utf-8');
|
||||||
|
const file_e = fs.readFileSync('data/e_many_teams.in', 'utf-8');
|
||||||
|
|
||||||
|
let totalScore = 0;
|
||||||
|
|
||||||
|
function main(file, char) {
|
||||||
|
const myArray = file.split('\n').map((line) => line.split(' '));
|
||||||
|
|
||||||
|
let finalPizzas = [];
|
||||||
|
|
||||||
|
const set = {
|
||||||
|
numberOfPizzas: parseInt(myArray[0][0]),
|
||||||
|
teams_2: parseInt(myArray[0][1]),
|
||||||
|
teams_3: parseInt(myArray[0][2]),
|
||||||
|
teams_4: parseInt(myArray[0][3]),
|
||||||
|
pizzas: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// Insert all pizzas in set
|
||||||
|
for (let i = 1; i < myArray.length; i++) {
|
||||||
|
let pizza = {};
|
||||||
|
|
||||||
|
pizza.id = i - 1;
|
||||||
|
pizza.numberOfIngredients = parseInt(myArray[i][0]);
|
||||||
|
pizza.ingredients = myArray[i].slice(1, myArray[i].length).sort();
|
||||||
|
|
||||||
|
set.pizzas.push(pizza);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort pizzas in descending order of most ingredients
|
||||||
|
set.pizzas.sort((a, b) => b.numberOfIngredients - a.numberOfIngredients);
|
||||||
|
|
||||||
|
let availablePizzas = [...set.pizzas];
|
||||||
|
|
||||||
|
/*
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
///////////////////////////////// 2 TEAMS //////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
*/
|
||||||
|
const find_for_two = () => {
|
||||||
|
let currentPizza = { ...availablePizzas[0] };
|
||||||
|
const selectedPizzas = [{ ...currentPizza }];
|
||||||
|
|
||||||
|
let mostDifferentPizzas = [];
|
||||||
|
for (let k = 1; k < availablePizzas.length; k++) {
|
||||||
|
let differentIngredients = availablePizzas[k].ingredients.length;
|
||||||
|
|
||||||
|
for (let l = 0; l < availablePizzas[k].ingredients.length; l++) {
|
||||||
|
if (
|
||||||
|
currentPizza.ingredients.includes(availablePizzas[k].ingredients[l])
|
||||||
|
) {
|
||||||
|
differentIngredients--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas.push({
|
||||||
|
...availablePizzas[k],
|
||||||
|
difference: differentIngredients,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas.sort((a, b) => b.difference - a.difference);
|
||||||
|
selectedPizzas.push({ ...mostDifferentPizzas[0] });
|
||||||
|
|
||||||
|
let totalDifference =
|
||||||
|
selectedPizzas[0].numberOfIngredients + selectedPizzas[1].difference;
|
||||||
|
|
||||||
|
finalPizzas.push({
|
||||||
|
teamSize: 2,
|
||||||
|
pizzas: [...selectedPizzas],
|
||||||
|
totalDifference: totalDifference,
|
||||||
|
});
|
||||||
|
|
||||||
|
availablePizzas = availablePizzas.filter(
|
||||||
|
(p) => !selectedPizzas.map((s) => s.id).includes(p.id)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
///////////////////////////////// 3 TEAMS //////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
*/
|
||||||
|
const find_for_three = () => {
|
||||||
|
let currentPizza = { ...availablePizzas[0] };
|
||||||
|
const selectedPizzas = [{ ...currentPizza }];
|
||||||
|
|
||||||
|
let mostDifferentPizzas = [];
|
||||||
|
for (let k = 1; k < availablePizzas.length; k++) {
|
||||||
|
let differentIngredients = availablePizzas[k].ingredients.length;
|
||||||
|
|
||||||
|
for (let l = 0; l < availablePizzas[k].ingredients.length; l++) {
|
||||||
|
if (
|
||||||
|
currentPizza.ingredients.includes(availablePizzas[k].ingredients[l])
|
||||||
|
) {
|
||||||
|
differentIngredients--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas.push({
|
||||||
|
...availablePizzas[k],
|
||||||
|
difference: differentIngredients,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas.sort((a, b) => b.difference - a.difference);
|
||||||
|
selectedPizzas.push({ ...mostDifferentPizzas[0] });
|
||||||
|
|
||||||
|
for (let m = 1; m < mostDifferentPizzas.length; m++) {
|
||||||
|
let differentIngredients = mostDifferentPizzas[m].difference;
|
||||||
|
|
||||||
|
for (let n = 0; n < mostDifferentPizzas[m].ingredients.length; n++) {
|
||||||
|
if (
|
||||||
|
mostDifferentPizzas[0].ingredients.includes(
|
||||||
|
mostDifferentPizzas[m].ingredients[n]
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
differentIngredients--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas[m].difference = differentIngredients;
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas.sort((a, b) => b.difference - a.difference);
|
||||||
|
selectedPizzas.push({ ...mostDifferentPizzas[1] });
|
||||||
|
|
||||||
|
let totalDifference =
|
||||||
|
selectedPizzas[0].numberOfIngredients +
|
||||||
|
selectedPizzas[1].difference +
|
||||||
|
selectedPizzas[2].difference;
|
||||||
|
|
||||||
|
finalPizzas.push({
|
||||||
|
teamSize: 3,
|
||||||
|
pizzas: [...selectedPizzas],
|
||||||
|
totalDifference: totalDifference,
|
||||||
|
});
|
||||||
|
|
||||||
|
availablePizzas = availablePizzas.filter(
|
||||||
|
(p) => !selectedPizzas.map((s) => s.id).includes(p.id)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
///////////////////////////////// 4 TEAMS //////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
*/
|
||||||
|
const find_for_four = () => {
|
||||||
|
let currentPizza = { ...availablePizzas[0] };
|
||||||
|
const selectedPizzas = [{ ...currentPizza }];
|
||||||
|
|
||||||
|
let mostDifferentPizzas = [];
|
||||||
|
for (let k = 1; k < availablePizzas.length; k++) {
|
||||||
|
let differentIngredients = availablePizzas[k].ingredients.length;
|
||||||
|
|
||||||
|
for (let l = 0; l < availablePizzas[k].ingredients.length; l++) {
|
||||||
|
if (
|
||||||
|
currentPizza.ingredients.includes(availablePizzas[k].ingredients[l])
|
||||||
|
) {
|
||||||
|
differentIngredients--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas.push({
|
||||||
|
...availablePizzas[k],
|
||||||
|
difference: differentIngredients,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas.sort((a, b) => b.difference - a.difference);
|
||||||
|
selectedPizzas.push({ ...mostDifferentPizzas[0] });
|
||||||
|
|
||||||
|
for (let m = 1; m < mostDifferentPizzas.length; m++) {
|
||||||
|
let differentIngredients = mostDifferentPizzas[m].difference;
|
||||||
|
|
||||||
|
for (let n = 0; n < mostDifferentPizzas[m].ingredients.length; n++) {
|
||||||
|
if (
|
||||||
|
mostDifferentPizzas[0].ingredients.includes(
|
||||||
|
mostDifferentPizzas[m].ingredients[n]
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
differentIngredients--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas[m].difference = differentIngredients;
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas.sort((a, b) => b.difference - a.difference);
|
||||||
|
selectedPizzas.push({ ...mostDifferentPizzas[1] });
|
||||||
|
|
||||||
|
for (let o = 2; o < mostDifferentPizzas.length; o++) {
|
||||||
|
let differentIngredients = mostDifferentPizzas[o].difference;
|
||||||
|
|
||||||
|
for (let p = 0; p < mostDifferentPizzas[o].ingredients.length; p++) {
|
||||||
|
if (
|
||||||
|
mostDifferentPizzas[1].ingredients.includes(
|
||||||
|
mostDifferentPizzas[o].ingredients[p]
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
differentIngredients--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas[o].difference = differentIngredients;
|
||||||
|
}
|
||||||
|
|
||||||
|
mostDifferentPizzas.sort((a, b) => b.difference - a.difference);
|
||||||
|
selectedPizzas.push({ ...mostDifferentPizzas[2] });
|
||||||
|
|
||||||
|
let totalDifference =
|
||||||
|
selectedPizzas[0].numberOfIngredients +
|
||||||
|
selectedPizzas[1].difference +
|
||||||
|
selectedPizzas[2].difference +
|
||||||
|
selectedPizzas[3].difference;
|
||||||
|
|
||||||
|
finalPizzas.push({
|
||||||
|
teamSize: 4,
|
||||||
|
pizzas: [...selectedPizzas],
|
||||||
|
totalDifference: totalDifference,
|
||||||
|
});
|
||||||
|
|
||||||
|
availablePizzas = availablePizzas.filter(
|
||||||
|
(p) => !selectedPizzas.map((s) => s.id).includes(p.id)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
while (availablePizzas.length > 0) {
|
||||||
|
if (
|
||||||
|
set.teams_2 + set.teams_3 + set.teams_4 === 0 ||
|
||||||
|
(availablePizzas.length === 2 && set.teams_2 === 0) ||
|
||||||
|
(availablePizzas.length === 3 && set.teams_3 === 0)
|
||||||
|
) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(availablePizzas.length % 2 !== 0 || set.teams_2 + set.teams_4 === 0) &&
|
||||||
|
set.teams_3 > 0
|
||||||
|
) {
|
||||||
|
find_for_three();
|
||||||
|
set.teams_3--;
|
||||||
|
} else {
|
||||||
|
if (availablePizzas.length > 2 && set.teams_4 > 0) {
|
||||||
|
find_for_four();
|
||||||
|
set.teams_4--;
|
||||||
|
} else {
|
||||||
|
find_for_two();
|
||||||
|
set.teams_2--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const finalScore = finalPizzas.reduce(
|
||||||
|
(result, item) => result + item.totalDifference * item.totalDifference,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`Score ${char}: ${finalScore}`);
|
||||||
|
totalScore += finalScore;
|
||||||
|
}
|
||||||
|
|
||||||
|
main(file_a, 'A');
|
||||||
|
main(file_b, 'B');
|
||||||
|
main(file_c, 'C');
|
||||||
|
main(file_d, 'D');
|
||||||
|
main(file_e, 'E');
|
||||||
|
|
||||||
|
console.log(`Total Score: ${totalScore}`);
|
Loading…
x
Reference in New Issue
Block a user