Skip to content

Instantly share code, notes, and snippets.

@Th0rgal
Last active September 19, 2021 16:32
Show Gist options
  • Save Th0rgal/6a027a35ff7ce67cc51d0c6100cd00a4 to your computer and use it in GitHub Desktop.
Save Th0rgal/6a027a35ff7ce67cc51d0c6100cd00a4 to your computer and use it in GitHub Desktop.
TD 1 Ocaml
let rec h x y =
let rec h2 x y acc =
if x = y then acc
else if x < y then h2 (x - 1) (y - 2) (acc + x + y)
else h2 (x - 1) y (acc * y)
in
h2 x y 1
let f1 =
let rec f1rec x =
if x <= 4 then (
Printf.printf "%d" x;
f1rec (x + 2))
in
f1rec 0
let f2 =
let rec subf2 x y =
if x <= 4 then (
Printf.printf "%d" (y - x);
subf2 (x + 2) (y - 1))
in
subf2 0 10
let f3 =
let rec subf3 x y =
if x <= 4 then (
Printf.printf "%d\n" 100;
subf3 (x + 1) (y - x))
in
subf3 0 5
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment