Skip to content

Instantly share code, notes, and snippets.

@Denommus
Last active August 29, 2015 13:59
Show Gist options
  • Save Denommus/10566040 to your computer and use it in GitHub Desktop.
Save Denommus/10566040 to your computer and use it in GitHub Desktop.
Cookie problem from GSoC 2014 in C
#include <stdio.h>
double calculateTime(double c, double f, double x) {
double totalTime = 0;
int n = 0;
double timeWithCurrent, timeForFarm, timeWithFarm;
do {
timeWithCurrent = x/((f*n)+2);
timeForFarm = c/((f*n)+2);
timeWithFarm = timeForFarm+(x/(((1+n)*f)+2));
if(timeWithFarm > timeWithCurrent) {
totalTime += timeWithCurrent;
break;
} else {
n += 1;
totalTime += timeForFarm;
}
} while (1);
return totalTime;
}
int main() {
printf("%.7f\n", calculateTime(30.0, 2.0, 100.0));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment