haha, if you want to get mathematical, you want to find the Greatest Common Divisor
d of two numbers
a and
b, and then the ratio
a:
b in lowest terms is
a/d:
b/d.
Now, if you're only looking at small numbers, say, you don't expect either
a or
b to be greater than 10, then it may be easiest to just manually have a trigger case for each possible combination. (In this case, I'd estimate less than 30 distinct triggers).
--
However, if you want to account for a very large number of cases (say if
a and
b potentially have unlimited magnitude), then... you can find
d by trial and error... try translating this into triggers:
CODE
test_val = min(a,b);
d = 0;
while ( d==0 && test_val > 0 )
if ( remainder(a,test_val)==0 && remainder(b,test_val)==0 )
d == test_val;
else
test_val == test_val - 1;
end
end
[sub]Written in the language MATLAB, for those who were wondering =P[/sub]
Alternatively, you can try to use Euclid's Algorithm to find the greatest common divisor
d. Euclid's algorithm works at the speed of light, and looks like this:
Divide
a by
b and find the remainder
r[sub]1[/sub]. Then divide
b by
r[sub]1[/sub] and find the remainder
r[sub]2[/sub]. Divide
r[sub]1[/sub] by
r[sub]2[/sub] and find the remainder
r[sub]3[/sub], and so on. Continue until
r[sub]n[/sub] = 0, and then
r[sub]n-1[/sub] =
d, the lowest common denominator.
[codebox]Example: find the greatest common divisor of 138 and 96.
138 = 1*96 + 42 (i.e.
r[sub]1[/sub] = 42)
96 = 2*42 + 12
42 = 3*12 + 6
12 = 2*6 (+ 0)
So the greatest common divisor of 138 and 96 is 6.
So the ratio 138:96 in lowest terms is 138/6:96/6 = 23:16[/codebox]I will be very impressed with anyone who can put this in their map