#include <stdlib.h>
#include <stdio.h>


//1.5*15 + 2*120 + 22.5 * 91 / 26 = 88.846


int main(int argc, char **argv){
	//double octanes[] = {};
	//double gallons[] = {};

	double octane_petrol = 87;//86.011;
	double octane_acetone = 120;

	double gallons_petrol = 0.0;
	double gallons_acetone = 0.5;

	double octane_mix = 0.0;
	double gallons_mix = 0.0;
	double octane_target = 94;
//	double gallons_target = 0.0;

	double gallons_capacity = 16;
	double octane_out = 0;
	double tmp1 = 0;

	gallons_mix = gallons_acetone;
	octane_mix = gallons_acetone*octane_acetone;
	octane_mix /= gallons_mix;

	printf("mix gallons: %0.3lf mix octane: %0.3lf\n", gallons_mix, octane_mix);
	//gallons_target*octane_mix + (gallons_capacity-gallons_target)*octane_petrol / gallons_capacity = octane_target

//T*M + (C-T)*P / C = O
//t=co−cpm−p


//octane_petrol = 100;
//octane_target = 75;
//octane_mix = 50;

	//gallons_target = gallons_capacity*octane_target - gallons_capacity*octane_petrol*octane_mix - octane_petrol;
	//gallons_target = gallons_capacity*octane_target - octane_petrol*gallons_petrol;
	//gallons_target /= gallons_mix;
	//gallons_target = gallons_capacity*octane_petrol - gallons_capacity*octane_target;
	//gallons_target /= octane_target - octane_mix;

//gallons_capacity*octane_target = gallons_mix*octane_mix + (gallons_capacity-gallons_mix)*octane_petrol;
//A*B = C*D + (A-C)*E;

//c=ab−af / d−f

	gallons_mix = gallons_capacity*octane_target - gallons_capacity*octane_petrol;
	gallons_mix /= octane_mix-octane_petrol;

//	printf("mix gallons needed to produce %0.3lfg of octane %0.3lf : %0.3lfg\n", gallons_capacity, octane_target, gallons_mix);




	gallons_petrol = gallons_capacity-gallons_acetone;
	tmp1 = gallons_petrol*octane_petrol + gallons_acetone*octane_acetone;
	octane_out = tmp1/gallons_capacity;

	printf("(gallons) acetone: %0.3lf petrol: %0.3lf\n", 
		gallons_acetone, gallons_petrol);
	printf("total gallons: %0.3lf\n", gallons_capacity);
	printf("mix octane: %0.3lf\n", octane_out);


	return 0;
}
