Other Software > Developer's Corner
Efficient way to find highest common denominator? (For reducing fractions.)
(1/1)
Hirudin:
I'm making some AutoHotkey scripts and need to reduce a fraction.
Can anyone help me find the most efficient way to find the highest common denominator between 2 numbers?
I figure I can do a brute force type thing where I make each number "numerator1" and "numerator2".
Take each numerator and divide it by a counter.
- If the results for each division are integers then I'd make the results the new numerators.
- If one of the results is not an integer then increase the counter over and over until the counter = the smaller of the numerators
But I figure there's probably a better way...
Hirudin:
Welp, I made a function that will do it. It uses a list of prime numbers (primes.txt) that must be in the same directory as the "Func_GreatestCommonDenominator.ahk" script.
Also included is an example ahk script that uses the function to reduce a fraction and report by how much the original was reduced.
GCD 1.1.rar (22.95 kB - downloaded 227 times.)
Eóin:
The Euclidean algorithm is considered to be quite efficient :)
Hirudin:
The Euclidean algorithm is considered to be quite efficient :)
-Eóin (July 15, 2007, 04:29 AM)
--- End quote ---
Whoa! Looks pretty efficient to me. Thanks Eóin!
Navigation
[0] Message Index
Go to full version