When you divide int by int, you will get int as result (fraction part will be discarded). To get float in result, you must make one of the numbers float. This can be done in two ways:
1. If you have number, you can add .0 to one of the values: 9.0 / 18
will give you 0.5
2. If your number is variable, then you have to use explicit type conversion: float(n) / 18
will give you 0.5 for n = 9
.
To find greatest common factor you can use next function:
func gcd(a: int, b: int) -> int:
return a if b == 0.0 else gcd(b, a % b)