Browse Source

5 Smallest Multiple

Mistivia 3 months ago
parent
commit
7c13c97b62
1 changed files with 25 additions and 0 deletions
  1. 25 0
      0005/main.tcl

+ 25 - 0
0005/main.tcl

@@ -0,0 +1,25 @@
+proc gcd {a b} {
+    if {$b > $a} {
+        set t $b
+        set b $a
+        set a $t
+    }
+    while {$b != 0} {
+        set t $b
+        set b [expr {$a % $b}]
+        set a $t
+    }
+    return $a
+}
+
+proc lcm {a b} {
+    set g [gcd $a $b]
+    return [expr {$g * ($a / $g) * ($b / $g)}]
+}
+
+set result 1
+for {set i 1} {$i <= 20} {incr i} {
+    set result [lcm $result $i]
+}
+
+puts $result