fork download
  1. let string_of_list to_s list =
  2. "[" ^ String.concat ", " (List.map to_s list) ^ "]"
  3. let print_list to_s list =
  4. print_newline (print_string (string_of_list to_s list))
  5. let diff list =
  6. List.map2 (-) (List.tl list) (List.rev (List.tl (List.rev list)))
  7. let diff_rec list =
  8. let rec aux acc = function
  9. | [] -> acc
  10. | _ :: [] -> acc
  11. | a :: (b :: _ as tail) -> aux (b - a :: acc) tail
  12. in
  13. List.rev (aux [] list)
  14. let () =
  15. let p = print_list string_of_int in
  16. p (diff [3;1;4;1;5;9;2;6;5]);
  17. p (diff_rec [3;1;4;1;5;9;2;6;5])
  18.  
Success #stdin #stdout 0s 4500KB
stdin
Standard input is empty
stdout
[-2, 3, -3, 4, 4, -7, 4, -1]
[-2, 3, -3, 4, 4, -7, 4, -1]