Skip to content

Instantly share code, notes, and snippets.

@xkrsz
Last active April 1, 2017 01:14
Show Gist options
  • Save xkrsz/8f87148ac70751498a08b9470b49263f to your computer and use it in GitHub Desktop.
Save xkrsz/8f87148ac70751498a08b9470b49263f to your computer and use it in GitHub Desktop.
Jebany robot
#include <iostream>
#include <math.h>
// 1500 * 60 s koniec
// naczynie 5l
// czas = 0 start, stężenie 0.8 = 4l substancji X i 1l wody
// pod koniec parzystej minuty robot wypuszcza 0.02l z naczynia
// pierwsze wypuszczenie = 119 s
// co 50 * 60 s robot dopełnia wodą naczynie do fula
// pierwsze dopełnienie = 51 * 60 s
float robot(float dropAmount) {
int n = 60;
float X = 4000,
W = 1000,
Xratio = 0.8,
totalAmount = 5000,
maxAmount = 5000,
// = 20,
totalFilled = 0;
for(int time = 0; time < 1500 * 60; time++) {
// at the end of every even minute
if((time + 1) % 120 == 0 && (time + 1) >= 120) {
X -= Xratio * dropAmount;
W -= (1.0 - Xratio) * dropAmount;
totalAmount = X + W;
//printf("\n%d", totalAmount);
}
// fill container
if(time == 51 * 60 ||
(time > (51 * 60) && time % (50 * 60) == 0)) {
// printf("\nBefore filling: %d mililiters and %f ratio", totalAmount, Xratio);
float fillAmount = maxAmount - totalAmount;
totalFilled += fillAmount;
W += fillAmount;
totalAmount = W + X;
Xratio = (float)X / (float)totalAmount;
// printf("\nAfter filling: %d mililiters and %f ratio", totalAmount, Xratio);
}
if (time % n == 0) {
//printf("\n\n---Minute %d---\nTotal: %fml\nW: %fml\nX: %fml\nX ratio: %f% / %f%\nTotal filled: %fml", time / 60, totalAmount, W, X, Xratio * 100, roundf(Xratio * 10000) / 100, totalFilled);
//std::cout << time / 60 << " " << totalAmount << " " << Xratio << " " << X << " " << W << " " << W+X << "\n";
}
}
return Xratio;
}
int main() {
float dropAmount = 28;
float ratio = 1337;
int i = 1;
while(ratio > 0.01) {
dropAmount += 0.000001;
if(i % 1000 == 0) {
printf("-----\nDrop amount: %fml\nRatio: %f\n-----", dropAmount, ratio);
}
//printf("\nTesting %fml drop", dropAmount);
ratio = robot(dropAmount);
i++;
}
printf("Found drop: %fml", dropAmount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment