feat: add sample gcd
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -4,6 +4,9 @@
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
*.cmi
|
||||
*.cmo
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
@@ -4,6 +4,14 @@ OCaml Language tests
|
||||
|
||||
https://ocaml.org/
|
||||
|
||||
<br>
|
||||
|
||||
Compile single file:
|
||||
```shell
|
||||
$ ocamlc -o gcd gcd.ml
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
Install on macOS
|
||||
```shell
|
||||
|
||||
18
gcd.ml
Normal file
18
gcd.ml
Normal file
@@ -0,0 +1,18 @@
|
||||
(* File gcd.ml *)
|
||||
let rec gcd a b =
|
||||
if b = 0 then a
|
||||
else gcd b (a mod b);;
|
||||
|
||||
let main () =
|
||||
let len = Array.length Sys.argv in
|
||||
Printf.printf "array length %d\n" len;
|
||||
if len < 3 then (
|
||||
Printf.printf "must have 2 args";
|
||||
exit 0;
|
||||
);
|
||||
let a = int_of_string Sys.argv.(1) in
|
||||
let b = int_of_string Sys.argv.(2) in
|
||||
Printf.printf "gcd of %d and %d is %d\n" a b (gcd a b);
|
||||
exit 0;;
|
||||
main ();;
|
||||
|
||||
Reference in New Issue
Block a user