Skip to content

Instantly share code, notes, and snippets.

@Californ1a
Last active December 13, 2018 15:09
Show Gist options
  • Save Californ1a/b0d4776f9c3b29c2610934cb258d3ca7 to your computer and use it in GitHub Desktop.
Save Californ1a/b0d4776f9c3b29c2610934cb258d3ca7 to your computer and use it in GitHub Desktop.
var 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
}
};
var transmute = {
oil: 0,
bowl: 0
};
var amount = 0;
function 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++;
}
}
function createOil() {
ingredients.salt.amount -= 20;
ingredients.energy.amount -= 20;
ingredients.oil.amount += 10;
transmute.oil++;
addSoup();
}
function createBowl() {
ingredients.oil.amount -= 10;
ingredients.energy.amount -= 10;
ingredients.bowl.amount += 10;
transmute.bowl++;
addSoup();
}
function 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();
}
}
}
function calcMain(soupIngredients) {
soupIngredients = soupIngredients[0]
ingredients.bowl.amount = soupIngredients[0];
ingredients.oil.amount = soupIngredients[1];
ingredients.salt.amount = soupIngredients[2];
ingredients.bamboo.amount = soupIngredients[3];
ingredients.mushroom.amount = soupIngredients[4];
ingredients.energy.amount = soupIngredients[5];
addSoup();
if (ingredients.bamboo.amount > 0 && ingredients.mushroom.amount > 0) {
multi();
}
var arr = Object.keys(ingredients);
amounts = arr.map(function(i) {
return ingredients[i].amount;
});
names = arr.map(function(i) {
return ingredients[i].name;
});
names.push("Total Soups");
amounts.push(amount);
//Object.entries(ingredients).map(function (i) {
// return i[1].amount
//});
return [
"Transmute oil " + transmute.oil + " times using " + transmute.oil*20 + " salt and " + transmute.oil*20 + " energy.",
"Transmute bowls " + transmute.bowl + " times using " + transmute.bowl*10 + " oil and " + transmute.bowl*10 + " energy",
"",
"Remaining Items",
names,
amounts
];
}
// console.log(JSON.stringify(ingredients, null, 2));
// console.log(amount);
//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