2022-01-20 14:06:42 +00:00
|
|
|
import fractions
|
|
|
|
|
2022-01-22 05:21:09 +00:00
|
|
|
from returns.maybe import Maybe, Nothing, Some
|
|
|
|
|
|
|
|
MAX_CAPACITY: int = 300
|
|
|
|
|
|
|
|
|
|
|
|
def ratio(
|
|
|
|
grade_in: int, grade_out: int, across_categories: bool
|
|
|
|
) -> Maybe[fractions.Fraction]:
|
|
|
|
trading_up = grade_out > grade_in
|
|
|
|
grade_base = 6 if trading_up else 3
|
|
|
|
grade_ratio = fractions.Fraction(grade_base ** grade_out, grade_base ** grade_in)
|
|
|
|
category_ratio = (
|
|
|
|
fractions.Fraction(6, 1) if across_categories else fractions.Fraction(1, 1)
|
|
|
|
)
|
|
|
|
result = grade_ratio * category_ratio
|
|
|
|
if max(result.numerator, result.denominator) > MAX_CAPACITY:
|
|
|
|
return Nothing
|
|
|
|
else:
|
|
|
|
return Some(result)
|