Skip to content

Instantly share code, notes, and snippets.

@tsu-nera
Created December 10, 2015 15:20
Show Gist options
  • Select an option

  • Save tsu-nera/6e8405a8531c5d6933a7 to your computer and use it in GitHub Desktop.

Select an option

Save tsu-nera/6e8405a8531c5d6933a7 to your computer and use it in GitHub Desktop.
SRM 675 Div2 250
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
class LengthUnitCalculator:
def calc(self, amount, fromUnit, toUnit):
if fromUnit == toUnit:
return amount
if fromUnit == "in":
if toUnit == "ft":
return amount / 12
elif toUnit == "yd":
return amount / (12 * 3)
elif toUnit == "mi":
return amount / (12 * 3 * 1760)
if fromUnit == "ft":
if toUnit == "in":
return amount * 12
elif toUnit == "yd":
return amount / 3
elif toUnit == "mi":
return amount / (3 * 1760)
if fromUnit == "yd":
if toUnit == "in":
return amount * 3 * 12
elif toUnit == "ft":
return amount * 3
elif toUnit == "mi":
return amount / 1760
if fromUnit == "mi":
if toUnit == "in":
return amount * 12 * 3 * 1760
elif toUnit == "ft":
return amount * 3 * 1760
elif toUnit == "yd":
return amount * 1760
return 0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment