fork download
  1. let sumnum n =
  2. let rec f n ret =
  3. if n < 10 then ret ^ (string_of_int n)
  4. else f (n - 9) (ret ^ "9") in
  5. let rec g n s ret =
  6. if n < 1 then ret
  7. else g (n - 1) (s ^ "0") (s :: ret) in
  8. g 5 (f n "") []
  9.  
  10. let string_of_list l =
  11. let rec f l ret = match l with
  12. [] -> ret
  13. | [a] -> ret ^ a
  14. | a :: b -> f b (ret ^ a ^ ",") in
  15. (f l "[") ^ "]"
  16.  
  17. let () = Scanf.scanf "%d" (fun x -> print_string (string_of_list (sumnum x)))
Success #stdin #stdout 0s 16168KB
stdin
12
stdout
[930000,93000,9300,930,93]