Jump to content

I made a food poisioning calculator


Dimpy

Recommended Posts

This program will calculate, on average, how many times you need to consume a food item in A18 to increase your max stamina to a certain amount. You can use it on ideone at this link, but it will work better if you compile it and use it at a terminal.

 

To use it in ideone, you'll have to click the "edit" button, then change the input values in the box below the source code.

Right now it's set to ask for the servings needed to go from 40 food to 140 food, with each serving restoring 10 food.

 

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

//You can change these numbers here to change the program:
const int MIN_FOOD = 20;
const float POISION_CHANCE = 0.04;



int main(){
float cur_food, food_restoration, end_food, servings_needed;


cout << "What is the value of your food meter currently?" << endl;
cin >> cur_food;

cout << "How much max stamina does food restore?" << endl;
cin >> food_restoration;

cout << "What level of food meter would you like to end up with?"<< endl;
cin >> end_food;



servings_needed = (
	log(1 - POISION_CHANCE*(cur_food - MIN_FOOD)/food_restoration) -
	log(1 - POISION_CHANCE*(end_food - MIN_FOOD)/food_restoration)
) / POISION_CHANCE;


cout <<	"Assuming your food meter can't go below " << MIN_FOOD << " and the food has a " 
	<< POISION_CHANCE*100 << "% chance of food poision, you will have to eat the food an average " 
	<< "of " << servings_needed << " times." << endl;

cout << "Without food poisioning, you'd only need to eat " << (end_food - cur_food)/food_restoration <<
	" times.\n" ;

return 0;
}


Link to comment
Share on other sites

or 1-(1-p)^n

where p is the food poisoning chance of the food you're eating (such as 0.04 for normal cooked food with no iron gut) and "n" is the number of food items you need to eat.

 

That will give you the total chance you'll get food poisoning somewhere during the process.

 

So if your max stamina is 25 out of 100 and you need to eat 13 grilled meat to get to 150/100 for max overage, with 0 points in iron gut (so a food poisoning chance of 0.04), it'll be: 1-(1-0.04)^13, which equals 0.4118, or 41.18%....so at level 1, getting food poisoning, and happening to have enough grilled meat to get your stamina back, you still have a bit more than a 2/5 chance of resetting right back to food poisoned...

Link to comment
Share on other sites

or 1-(1-p)^n

where p is the food poisoning chance of the food you're eating (such as 0.04 for normal cooked food with no iron gut) and "n" is the number of food items you need to eat.

 

That will give you the total chance you'll get food poisoning somewhere during the process.

 

So if your max stamina is 25 out of 100 and you need to eat 13 grilled meat to get to 150/100 for max overage, with 0 points in iron gut (so a food poisoning chance of 0.04), it'll be: 1-(1-0.04)^13, which equals 0.4118, or 41.18%....so at level 1, getting food poisoning, and happening to have enough grilled meat to get your stamina back, you still have a bit more than a 2/5 chance of resetting right back to food poisoned...

 

Yeah, combinational probability will get you the chance of getting poisoned from a certain amount of eatings, which is different from what I was doing.

 

What my calculator does is find "n". Finding "n" is not as simple as dividing the hunger discrepancy by the amount restored by a serving, because if you end up vomiting that means you're going to have to spend more food getting back up, and the extra food you need to get back up is proportional to the amount of food you had when you ate the poisoned food. Instead of 12.5 grilled meat, you'd end up needing to, on average, eat 17.84 grilled meat, which works out to be a 51% food poisoning chance at some point according to your formula.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...