Skip to content

Instantly share code, notes, and snippets.

@valkheim
Created April 9, 2018 07:09
Show Gist options
  • Save valkheim/7b0f582bb87ce3ccc2db98732e8be7a7 to your computer and use it in GitHub Desktop.
Save valkheim/7b0f582bb87ce3ccc2db98732e8be7a7 to your computer and use it in GitHub Desktop.
chameau
let rec appartenance f e = match e with
|[]-> false
|t::q-> if f=t then true else (appartenance f q);;
let res = appartenance ["valkheim"] ["valkheim";"niflheim";"muspelheim"];;
let rec ajout f e = match e with
|[]-> [f]
|t::q-> if f=t then e else t::(ajout f q);;
let res = ajout "4" ["1";"2";"3"]
let rec printl xs =
let rec _printl xs i =
match (xs,i) with
([], i) -> Printf.printf "]\n" ; ()
| (t::q, 0) -> Printf.printf "[%s" t ; _printl q 1
| (t::q, i) -> Printf.printf ";%s" t ; _printl q i
in
_printl xs 0;
;;
printl res
let rec inclusion e1 e2 = match e1 with
[] -> true
| t::q -> if appartenance t e2 then inclusion q e2 else false
;;
let res = inclusion ["valkheim"] ["valkheim";"niflheim";"muspelheim"];;
Printf.printf "inclusion: %b\n" res
let egalite e1 e2 = (inclusion e1 e2) && (inclusion e2 e1);;
let ret = egalite ["valkheim"] ["valkheim";"niflheim";"muspelheim"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment