- Codice:
let rec rev l = match l with
[] -> []
| h::t -> rev t @ [h];;
let rec f l = match l with
[] -> 0
| h::t -> let k = rev l in match k with
[] -> 0
| k::v -> k * 2 + f v;;
Sapreste aiutarmi a risolvere questo problema?
let rec rev l = match l with
[] -> []
| h::t -> rev t @ [h];;
let rec f l = match l with
[] -> 0
| h::t -> let k = rev l in match k with
[] -> 0
| k::v -> k * 2 + f v;;
let reverse lst = reverseAcc [] lst
let rec reverseAcc acc lst =
match lst with
| [] -> acc
| h::t = reverseAcc (h @ acc) t
let twoPowers n =
let rec twoPowersHelper s n = if n > 0 then (s @ twoPowersHelper (2 * s) (n - 1)) else [] in
twoPowersHelper 1 n
Visitano il forum: Nessuno e 1 ospite