Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type col = Rosso | Giallo | Verde | Blu
- type 'a col_assoc = (col * 'a list) list
- type 'a tree = Empty | Tr of 'a * 'a tree * 'a tree
- let colore x lst = fst (List.find (fun (a,b) -> List.mem x b) lst)
- let next = function
- | Rosso | Giallo | Verde -> Blu
- | Blu -> Rosso
- let path_to k colori =
- let rec aux c sol = function
- | Empty -> raise Fail
- | Tr(x,_,_) when (colore x colori)=c -> raise Fail
- | Tr(x,Empty,Empty) -> if x=k then (List.rev (x::sol)) else raise Fail
- | Tr(x,lt,rt) -> let c,s = (colore x colori),(x::sol) in
- try aux c s lt with _ -> aux c s rt
- in function
- | Tr(x,_,_) as t -> aux (next (colore x colori)) [] t
- | Empty -> raise Fail
Advertisement
Add Comment
Please, Sign In to add comment