Skip to content

Commit 940ebe0

Browse files
authored
Merge pull request #11 from ubsan/add-ocaml
add ocaml to euclidean
2 parents 1b879b6 + e679c07 commit 940ebe0

File tree

1 file changed

+23
-0
lines changed
  • chapters/fundamental_algorithms/euclidean_algorithm

1 file changed

+23
-0
lines changed

chapters/fundamental_algorithms/euclidean_algorithm/euclidean.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,26 @@ fn main() {
331331
println!("{}", chk2);
332332
}
333333
```
334+
335+
### OCaml
336+
337+
```ocaml
338+
let rec euclid_mod a b =
339+
if b = 0 then
340+
a
341+
else
342+
euclid_mod b (a mod b)
343+
344+
let rec euclid_sub a b =
345+
if a = b then
346+
a
347+
else if a < b then
348+
euclid_sub a (b - a)
349+
else
350+
euclid_sub (a - b) b
351+
352+
let chk1 = euclid_mod (64 * 67) (64 * 81)
353+
let chk2 = euclid_sub (128 * 12) (128 * 77)
354+
let () = print_string ((int_of_string chk1) ^ "\n")
355+
let () = print_string ((int_of_string chk2) ^ "\n")
356+
```

0 commit comments

Comments
 (0)