-
-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy patheuclidean.m
More file actions
37 lines (27 loc) · 624 Bytes
/
euclidean.m
File metadata and controls
37 lines (27 loc) · 624 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Submitted by Max Weinstein
function gcd = euclidSub(a,b)
a = abs(a);
b = abs(b);
while a ~= b
if a > b
a = a - b;
else
b = b - a;
end
end
gcd = a;
end
function gcd = euclidMod(a,b)
a=abs(a);
b=abs(b);
while b > 0
temp = b;
b = mod(a,b);
a = temp;
end
gcd = a;
end
function euclid()
['[#] Modulus-based euclidean algorithm result: ',num2str(euclidMod(64 * 67, 64 * 81))]
['[#] Subtraction-based euclidean algorithm result: ',num2str(euclidSub(128 * 12, 128 * 77))]
end