Skip to content

Commit ae7e917

Browse files
authored
Merge pull request keon#52 from ofek/master
add lcm
2 parents 89f4e49 + 4597ff0 commit ae7e917

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Minimal and clean example implementations of data structures and algorithms in P
9393
- [valid_sudoku](map/valid_sudoku.py)
9494
- [math](math)
9595
- [extended_gcd](math/extended_gcd.py)
96-
- [gcd](math/gcd.py)
96+
- [gcd/lcm](math/gcd.py)
9797
- [prime_test](math/prime_test.py)
9898
- [primes_sieve_of_eratosthenes](math/primes_sieve_of_eratosthenes.py)
9999
- [generate_strobogrammtic](math/generate_strobogrammtic.py)

math/gcd.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
'''
2-
Computes gcd of integers a and b using Euclid's Algorithm
3-
'''
4-
5-
61
def gcd(a, b):
2+
"""Computes the greatest common divisor of integers a and b using
3+
Euclid's Algorithm.
4+
"""
75
while True:
86
if b == 0:
97
return a
108
a, b = b, a % b
9+
10+
11+
def lcm(a, b):
12+
"""Computes the lowest common multiple of integers a and b."""
13+
return a * b / gcd(a, b)

0 commit comments

Comments
 (0)