Skip to content

Instantly share code, notes, and snippets.

@Californ1a
Last active December 13, 2018 15:09
Show Gist options
  • Save Californ1a/f59a07e36ce74123db3050be3eb665fe to your computer and use it in GitHub Desktop.
Save Californ1a/f59a07e36ce74123db3050be3eb665fe to your computer and use it in GitHub Desktop.
calculate shark soup amounts with transmutations of oil and bowls
const ingredients = {
bowl: {
name: "Shiny tortle shell bowls",
amount: 1
},
oil: {
name: "Wobbegong Oil",
amount: 1
},
salt: {
name: "Alaea Sea Salt",
amount: 5000
},
bamboo: {
name: "Bundles of Bamboo",
amount: 500
},
mushroom: {
name: "Sliced Mushrooms",
amount: 500
},
energy: {
name: "Ancestral Energy",
amount: 1200
}
};
const transmute = {
oil: 0,
bowl: 0
};
let amount = 0;
const addSoup = () => {
while (ingredients.bowl.amount > 0 && ingredients.oil.amount > 0 && ingredients.salt.amount > 0 && ingredients.bamboo.amount > 0 && ingredients.mushroom.amount > 0) {
ingredients.bowl.amount -= 1;
ingredients.oil.amount -= 1;
ingredients.salt.amount -= 1;
ingredients.bamboo.amount -= 1;
ingredients.mushroom.amount -= 1;
amount++;
}
};
const createOil = () => {
ingredients.salt.amount -= 20;
ingredients.energy.amount -= 20;
ingredients.oil.amount += 10;
transmute.oil++;
addSoup();
};
const createBowl = () => {
ingredients.oil.amount -= 10;
ingredients.energy.amount -= 10;
ingredients.bowl.amount += 10;
transmute.bowl++;
addSoup();
};
const multi = () => {
while ((ingredients.salt.amount - 20 >= 0 && ingredients.energy.amount - 20 >= 0) || (ingredients.oil.amount - 10 >= 0 && ingredients.energy.amount - 10 >= 0)) {
if (ingredients.salt.amount - 20 >= 0 && ingredients.energy.amount - 20 >= 0) {
createOil();
}
if (ingredients.oil.amount - 10 >= 0 && ingredients.energy.amount - 10 >= 0) {
createBowl();
}
}
};
addSoup();
if (ingredients.bamboo.amount > 0 && ingredients.mushroom.amount > 0) {
multi();
}
console.log(`Transmute oil ${transmute.oil} times using ${transmute.oil*20} salt and ${transmute.oil*20} energy.\nTransmute shells ${transmute.bowl} times using ${transmute.bowl*10} oil and ${transmute.bowl*10} energy\n\n\nTotal amount of soups: ${amount}\n\n--Remaining Items--`);
//node
// let output = "";
// for (let i = 0; i <= Object.keys(ingredients).length - 1; i++) {
// const key = Object.keys(ingredients)[i];
// output += (`\n${ingredients[key].name}\t${ingredients[key].amount}`);
// }
// console.log(output);
//browser
console.table(ingredients);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment