From 0b32086a1fc8ceef44cd904c1f5c3ca0605dae56 Mon Sep 17 00:00:00 2001 From: mgstabrani Date: Sun, 24 May 2026 12:58:19 +0700 Subject: [PATCH 1/4] feat(math): introduce lcm function --- math/lcm.jule | 16 ++++++++++++++++ math/lcm_test.jule | 12 ++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 math/lcm.jule create mode 100644 math/lcm_test.jule diff --git a/math/lcm.jule b/math/lcm.jule new file mode 100644 index 0000000..d363d6f --- /dev/null +++ b/math/lcm.jule @@ -0,0 +1,16 @@ +fn Lcm(a: int, b: int): int { + if a == 0 || b == 0 { + return 0 + } + + let mut x = a + if x < 0 { + x = -x + } + let mut y = b + if y < 0 { + y = -y + } + + return (x / GCD(x, y)) * y +} \ No newline at end of file diff --git a/math/lcm_test.jule b/math/lcm_test.jule new file mode 100644 index 0000000..9af7146 --- /dev/null +++ b/math/lcm_test.jule @@ -0,0 +1,12 @@ +#build test + +use "std/testing" + +#test +fn testLcm(t: &testing::T) { + t.Assert(Lcm(0, 7) == 0, "lcm of zero and 7 should be 0") + t.Assert(Lcm(4, 6) == 12, "lcm of 4 and 6 should be 12") + t.Assert(Lcm(21, 6) == 42, "lcm of 21 and 6 should be 42") + t.Assert(Lcm(-8, 12) == 24, "lcm should be positive for negative inputs") + t.Assert(Lcm(-9, -6) == 18, "lcm should be positive for two negatives") +} \ No newline at end of file From ed3e47f602468c02710726bfcf3a5cc91bf5afda Mon Sep 17 00:00:00 2001 From: mgstabrani Date: Sun, 24 May 2026 13:13:51 +0700 Subject: [PATCH 2/4] refactor: uppercase the lcm function --- math/lcm.jule | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm.jule b/math/lcm.jule index d363d6f..e36a388 100644 --- a/math/lcm.jule +++ b/math/lcm.jule @@ -1,4 +1,4 @@ -fn Lcm(a: int, b: int): int { +fn LCM(a: int, b: int): int { if a == 0 || b == 0 { return 0 } From 8c4b1800acbed821a77c0a20d8f48de2cd2d380a Mon Sep 17 00:00:00 2001 From: mgstabrani Date: Sun, 24 May 2026 13:14:49 +0700 Subject: [PATCH 3/4] test: uppercase the lcm function --- math/lcm_test.jule | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/math/lcm_test.jule b/math/lcm_test.jule index 9af7146..5f96d06 100644 --- a/math/lcm_test.jule +++ b/math/lcm_test.jule @@ -4,9 +4,9 @@ use "std/testing" #test fn testLcm(t: &testing::T) { - t.Assert(Lcm(0, 7) == 0, "lcm of zero and 7 should be 0") - t.Assert(Lcm(4, 6) == 12, "lcm of 4 and 6 should be 12") - t.Assert(Lcm(21, 6) == 42, "lcm of 21 and 6 should be 42") - t.Assert(Lcm(-8, 12) == 24, "lcm should be positive for negative inputs") - t.Assert(Lcm(-9, -6) == 18, "lcm should be positive for two negatives") + t.Assert(LCM(0, 7) == 0, "lcm of zero and 7 should be 0") + t.Assert(LCM(4, 6) == 12, "lcm of 4 and 6 should be 12") + t.Assert(LCM(21, 6) == 42, "lcm of 21 and 6 should be 42") + t.Assert(LCM(-8, 12) == 24, "lcm should be positive for negative inputs") + t.Assert(LCM(-9, -6) == 18, "lcm should be positive for two negatives") } \ No newline at end of file From bb93a920b9790d8997cdf0b37c9782d284d3fd87 Mon Sep 17 00:00:00 2001 From: "Mgs. Tabrani" Date: Sun, 24 May 2026 17:46:49 +0700 Subject: [PATCH 4/4] test: update testLcm to testLCM Co-authored-by: Mertcan D. <54983926+mertcandav@users.noreply.github.com> --- math/lcm_test.jule | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/math/lcm_test.jule b/math/lcm_test.jule index 5f96d06..d2aed6d 100644 --- a/math/lcm_test.jule +++ b/math/lcm_test.jule @@ -3,7 +3,7 @@ use "std/testing" #test -fn testLcm(t: &testing::T) { +fn testLCM(t: &testing::T) { t.Assert(LCM(0, 7) == 0, "lcm of zero and 7 should be 0") t.Assert(LCM(4, 6) == 12, "lcm of 4 and 6 should be 12") t.Assert(LCM(21, 6) == 42, "lcm of 21 and 6 should be 42")