Skip to content

Instantly share code, notes, and snippets.

@JacobSanford
Created February 24, 2014 19:56
Show Gist options
  • Save JacobSanford/9195762 to your computer and use it in GitHub Desktop.
Save JacobSanford/9195762 to your computer and use it in GitHub Desktop.
fractional_equivalents = {
'1/32' : 0.03125,
'1/16' : 0.06250,
'3/32' : 0.09375,
'1/8' : 0.12500,
'5/32' : 0.15625,
'3/16' : 0.18750,
'7/32' : 0.21875,
'1/4' : 0.25000,
'9/32' : 0.28125,
'5/16' : 0.31250,
'11/32' : 0.34375,
'3/8' : 0.37500,
'13/32' : 0.40625,
'7/16' : 0.43750,
'15/32' : 0.46875,
'1/2' : 0.50000,
'17/32' : 0.53125,
'9/16' : 0.56250,
'19/32' : 0.59375,
'5/8' : 0.62500,
'21/32' : 0.65625,
'11/16' : 0.68750,
'23/32' : 0.71875,
'3/4' : 0.75000,
'25/32' : 0.78125,
'13/16' : 0.81250,
'27/32' : 0.84375,
'7/8' : 0.87500,
'29/32' : 0.90625,
'15/16' : 0.93750,
'31/32' : 0.96875,
}
closest_key, closest_value = min(fractional_equivalents.items(), key=lambda (_, v): abs(v - remainder_value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment