From dad487fde327ba7743e93d84f27f790e39972252 Mon Sep 17 00:00:00 2001 From: d_m Date: Fri, 12 Apr 2024 18:24:54 -0400 Subject: [PATCH] gcd + lcm + weird bug --- demo.modal | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/demo.modal b/demo.modal index 3e4a574..2186f5c 100644 --- a/demo.modal +++ b/demo.modal @@ -19,6 +19,7 @@ <> ((binary 9)) ((1 (0 (0 (1 ()))))) -- ( binary to decimal digit ) +<> ((decimal ())) (0) <> ((decimal (0 ()))) (0) <> ((decimal (1 ()))) (1) <> ((decimal (0 (1 ())))) (2) @@ -203,4 +204,13 @@ <> ((pow ?x (0 ?k))) ((pow (mul ?x ?x) ?k)) <> ((pow ?x (1 ?k))) ((mul ?x (pow (mul ?x ?x) ?k))) -(str (pow (int 13) (int 10))) +-- ( greatest common denominator ) +<> ((gcd ?a ?b)) ((gcd1 ?a ?b (cmp ?b (0 ())))) +<> ((gcd1 ?a ?b #eq)) (?a) +<> ((gcd1 ?a ?b #gt)) ((gcd ?b (mod ?a ?b))) +<> ((gcd1 ?a ?b #lt)) ((gcd ?b (mod ?a ?b))) + +-- ( least common multiple ) +<> ((lcm ?a ?b)) ((mul ?a (div ?b (gcd ?a ?b)))) + +(str (lcm (int 1000) (int 777)))