User Tools

Site Tools


ex-l5-sol

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ex-l5-sol [2014/10/28 15:24]
t.cimoli
ex-l5-sol [2015/10/08 15:20] (current)
Line 36: Line 36:
                    in intrev (n/10) cifra  in intrev n 0 ;;                    in intrev (n/10) cifra  in intrev n 0 ;;
 let ispalindrome n = (n = intRevert n);; let ispalindrome n = (n = intRevert n);;
-</​code>​Alternativa con utilizzo delle liste: '''​intToList'''​ trasforma un intero nella lista delle sue cifre<​code ocaml>​let intToList n = if n < 10 then [n]  +</​code>​Alternativa con utilizzo delle liste: '''​intToList'''​ trasforma un intero nella lista delle sue cifre<​code ocaml>​let ​rec intToList n = if n < 10 then [n] else 
-       else let rec f n acc = if n = 0 then acc  +        let cifra = n mod 10 in  ​(listaCifreRec ​(n / 10)) @[cifra] ;;</​code>'''​reverse'''​ inverte una lista<​code ocaml>​let reverse l = 
-                              ​else ​let resto = n mod 10  +
-                                   in (n/​10) ​(resto::accin f n [];;</​code>'''​reverse'''​ inverte una lista<​code ocaml>​let reverse l = +
     let rec reverse'​ l acc = match l with     let rec reverse'​ l acc = match l with
         [] -> acc          [] -> acc 
ex-l5-sol.txt · Last modified: 2015/10/08 15:20 (external edit)