Skip to content

Instantly share code, notes, and snippets.

@terrycojones
Created November 15, 2017 22:50
Show Gist options
  • Save terrycojones/f2576e85742cb0e15e67f40b4a15e819 to your computer and use it in GitHub Desktop.
Save terrycojones/f2576e85742cb0e15e67f40b4a15e819 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function, division
from math import pi
best = []
bestError = 1e6
for front in range(20, 55):
for rear in range(10, 33):
ratio = front / rear
error = abs(pi - ratio)
if error < bestError:
bestError = error
best = [(front, rear)]
elif error == bestError:
best.append((front, rear))
print('Best ratio%s:' % '' if len(best) == 1 else 's')
for front, rear in best:
print('\tfront=%d rear=%d' % (front, rear))
print('Error:', bestError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment