Created
November 15, 2017 22:50
-
-
Save terrycojones/f2576e85742cb0e15e67f40b4a15e819 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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