Created
November 14, 2020 09:22
-
-
Save danba340/09b87459a56d81eb60f5eea8685d11e9 to your computer and use it in GitHub Desktop.
Codingame Fall Challenge 2020 Boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.error('Debug messages...'); | |
function canBrew(inventory, order) { | |
const canBrew = true | |
for(const [index, delta] of order.deltas.entries()) { | |
if(delta > inventory[index]){ | |
canBrew = false | |
} | |
} | |
return canBrew | |
} | |
function orderByRupies(a,b) { | |
return b.rupies - a.rupies | |
} | |
while (true) { | |
const actionCount = parseInt(readline()); // the number of spells and recipes in play | |
const orders = [] | |
const inventory = [] | |
for (let i = 0; i < actionCount; i++) { | |
var inputs = readline().split(' '); | |
const actionId = parseInt(inputs[0]); // the unique ID of this spell or recipe | |
const actionType = inputs[1]; // in the first league: BREW; later: CAST, OPPONENT_CAST, LEARN, BREW | |
const delta0 = parseInt(inputs[2]); // tier-0 ingredient change | |
const delta1 = parseInt(inputs[3]); // tier-1 ingredient change | |
const delta2 = parseInt(inputs[4]); // tier-2 ingredient change | |
const delta3 = parseInt(inputs[5]); // tier-3 ingredient change | |
const price = parseInt(inputs[6]); // the price in rupees if this is a potion | |
const tomeIndex = parseInt(inputs[7]); // in the first two leagues: always 0; later: the index in the tome if this is a tome spell, equal to the read-ahead tax; For brews, this is the value of the current urgency bonus | |
const taxCount = parseInt(inputs[8]); // in the first two leagues: always 0; later: the amount of taxed tier-0 ingredients you gain from learning this spell; For brews, this is how many times you can still gain an urgency bonus | |
const castable = inputs[9] !== '0'; // in the first league: always 0; later: 1 if this is a castable player spell | |
const repeatable = inputs[10] !== '0'; // for the first two leagues: always 0; later: 1 if this is a repeatable player spell | |
orders.push({ | |
id: actionId, | |
rupies: price, | |
deltas: [delta0,delta1,delta2,delta3] | |
}) | |
} | |
for (let i = 0; i < 2; i++) { | |
var inputs = readline().split(' '); | |
const inv0 = parseInt(inputs[0]); // tier-0 ingredients in inventory | |
const inv1 = parseInt(inputs[1]); | |
const inv2 = parseInt(inputs[2]); | |
const inv3 = parseInt(inputs[3]); | |
const score = parseInt(inputs[4]); // amount of rupees | |
inventory.push(inv0, inv1, inv2, inv3) | |
} | |
const brewableOrders = orders.filter(order => canBrew(inventory, order)) | |
const brewableOrdersByMostRupies = brewableOrders.sort(orderByRupies) | |
// in the first league: BREW <id> | WAIT; later: BREW <id> | CAST <id> [<times>] | LEARN <id> | REST | WAIT | |
if(brewableOrders.length){ | |
console.log(`BREW ${brewableOrdersByMostRupies[0].id}`); | |
} else { | |
console.log(`WAIT`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fastnat på
willHelpGoalSpell
. Men hoppas du kan få nån inspiration från detta: