Skip to content

Commit 2cdd003

Browse files
committed
Add GCD and LCM utility functions to Python snippets
1 parent 448df1a commit 2cdd003

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

public/data/python.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,44 @@
187187
],
188188
"tags": ["python", "math", "prime", "check"],
189189
"author": "dostonnabotov"
190+
},
191+
{
192+
"title": "Find the greatest common divisor (GCD)",
193+
"description": "Finds the greatest common divisor of two numbers.",
194+
"code": [
195+
"def gcd(a, b):",
196+
" while b:",
197+
" a, b = b, a % b",
198+
" return a",
199+
"",
200+
"# Usage:",
201+
"print(gcd(12, 15)) # Output: 3"
202+
],
203+
"tags": ["python", "math", "gcd", "utility"],
204+
"author": "SteliosGee"
205+
},
206+
{
207+
"title": "Find the least common multiple (LCM)",
208+
"description": "Finds the least common multiple of two numbers.",
209+
"code": [
210+
"def lcm(a, b):",
211+
" if a > b:",
212+
" greater = a",
213+
" else:",
214+
" greater = b",
215+
"",
216+
" while True:",
217+
" if greater % a == 0 and greater % b == 0:",
218+
" lcm = greater",
219+
" break",
220+
" greater += 1",
221+
" return lcm",
222+
"",
223+
"# Usage:",
224+
"print(lcm(4, 6)) # Output: 12"
225+
],
226+
"tags": ["python", "math", "lcm", "utility"],
227+
"author": "SteliosGee"
190228
}
191229
]
192230
},

0 commit comments

Comments
 (0)