Skip to content

Instantly share code, notes, and snippets.

Created October 21, 2014 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e760473080c3743451ef to your computer and use it in GitHub Desktop.
Save anonymous/e760473080c3743451ef to your computer and use it in GitHub Desktop.
import numpy
found=False
for va0 in numpy.arange(1,10):
if found:
break
print "Calculating:",va0,"/10"
va1=10-va0
for vb0 in numpy.arange(1,10):
if va0==vb0:
continue
vb1=16-vb0
for vc0 in numpy.arange(0,10):
vc1=26-vc0
for p0 in numpy.arange(0,10,0.01):
p1 = -p0*1.0*(va0-vb0)/(va1-vb1)
if(abs(35-p0*vc0-p1*vc1)<1e-5 and
abs(35-p0*va0-p1*va1)<1e-5 and
abs(35-p0*vb0-p1*vb1)<1e-5):
_p0=p0
_p1=p1
_va0=va0
_va1=va1
_vb0=vb0
_vb1=vb1
_vc0=vc0
_vc1=vc1
found = True
break
if found:
print "First price was",_p0,"and then",_p1
print "Farmer A sold",_va0,"before lunch and then",_va1
print "Farmer B sold",_vc0,"before lunch and then",_vb1
print "Farmer C sold",_vb0,"before lunch and then",_vc1
else:
print "Not found"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment