Hello everyone ,
In order to prepare an exam which is in one week , i’ve tried many things to solve this problem , but i actually miss a part something , i can’t figure it out …
The following exercice is this one
type hydra= Node of hydra list
The arity of a node of a hydra is its number of “girls”. ̨
1)
Write ̨ a ̨ function ̨ arite_max : hydra-> int
which calculates the maximum arity of a node in a hydra. ̨
I’ve tried this : ( this is quite awfull , but was the closest to the result I need to find…)
let rec arite h =
match h with
| Node([ ])->0
| Node(a :: b)-> 1 + arite (Node(b))
let rec aritemax h =
match h with
|Node([ ])->0
|Node(a :: [ ])-> aritemax a
|Node(a:: b ::c)->max(arite (Node(a:: b ::c))) (arite (Node( c )))
but when I test it with following examples :
# let _ = aritemax (Node([Node([Node([]);Node([]);Node([]);Node([])]);Node([])]));;
- : int = 2
# let _ = aritemax (Node([Node([Node([]);Node([]);Node([])])]));;
- : int = 3
# let _ = aritemax (Node([Node([Node([Node([]);Node([]);Node([]);Node([]);Node([])])])]));;
- : int = 5
If i get correctly the exercice , I think the first example shoud return 4 but seems to stop the level before it can calcule it …
If someone is familiar to this and can help me ( just an idea is enough ) , thanks a lot & happy new year !
For everyone else , Happy new year !