This is my notepad where i collect the useful snippets of OpenSCAD code that i use over and over. Some better curated than others, some formatted for clarity some for efficiency.
Sunday, May 21, 2017
Euclid's algorithm for finding the Greatest Common Divisor and Least Common Multiple
Euclid's algorithm for finding the Greatest Common Divisor of two numbers.
And its partner the Least Common Multiple
Usage:
echo(gcd(90,15));
echo(lcm(5,4));
function gcd(a,b)=
a<=0||b<=0?min(sign(a),sign(b)):
a % b==0?b:
gcd(b,a % b);
function lcm(a,b)= a * (b / gcd(a, b));
No comments:
Post a Comment