Just in case anyone wants to see the code (Python3) here it is. Making it public guarantees it's wrong …
import itertools # supports permutations
import fractions # for rational arithmetic
metric = [ 20, 30, 45, 50, 60, 60, 65, 70, 75, 80, 85 ]
imperial280 = [ 20, 25, 30, 40, 45, 50, 55, 60, 63, 65, 70, 75, 80, 80 ]
imperial = [ 40, 90, 75, 50, 60, 66, 70, 80, 65, 42 ]
extras = list( range( 25, 95, 5 ) )
gears = imperial + extras
headstock = 40
if gears == metric:
leadscrew = fractions.Fraction( 3, 1 ) # WM280 Metric
else:
#leadscrew = fractions.Fraction( 1, 8 ) # WM280 Imperial
leadscrew = fractions.Fraction( 1, 12 ) # WM240 Imperial
# Basic gear chain formula. NB 40 is the fixed headstock gear on some lathes
# 40 A C
# ratio = — . – . – . Leadscrew
# A B D
possibles = []
# calculate the ratio of each permutation and add to the possibles list
for a,b,c,d in itertools.permutations( gears, 4 ):
ha = fractions.Fraction( headstock, a )
ab = fractions.Fraction( a, b )
cd = fractions.Fraction( c, d )
ratio = ha * ab * cd * leadscrew
possibles.append( (a,b,c,d,ratio) )
# Remove duplicates by converting the possibles List to a Set
possibles = set( possibles )
# Sort the set of possibles by ratio
possibles = sorted( possibles, key=lambda possibles : possibles[4] )
# Output the results
print( "{:2s} {:2s} {:2s} {:2s} {:^8s} {:^6s} {:^6s}".
format("A","B","C","D","ratio","metric", "tpi"
)
for a,b,c,d,r in possibles:
if gears == metric:
print( "{:2d} {:2d} {:2d} {:2d} {:^8s} {:6.4g} {:6.4g}".
format(a, b, c, d, str(r), float(r), float(r) * 25.4 ))
else:
print( "{:2d} {:2d} {:2d} {:2d} {:^8s} {:6.4f} {:6.4g}".
format(a, b, c, d, str(r), 25.4 * float(r), 1/float(r) ))