Paste Description for python program to solve the prob
My answer to http://ask.metafilter.com/64035/Equation-solving-help-for-the-intellectually-challenged
python program to solve the prob
- # Solve original equation for y
- # x + y - x*y = 79
- # y - x*y = 79 - x
- # y * (1-x) = 79 - x
- # y = (79-x) / (1-x)
- # Find the value for y using integer math
- # then check whether this gives the exact value
- def candidate(x):
- y = (79-x) / (1-x)
- z = x + y - (x*y)
- if y != 0 and z == 79: print x, y
- # Starting at x=2, try x and -x as candidates
- # Zero is ruled out by the problem statement, and
- # 1 causes division by zero so it can't be a valid 'x' either
- # just keep going until interrupted, though there don't seem to be any
- # integer solutions for |x| > 77
- def main():
- from itertools import count
- try:
- for x in count(2):
- candidate(x)
- candidate(-x)
- except KeyboardInterrupt:
- print "last number considered:", x
- main()