fork download
  1. let range a b =
  2. let rec aux a b acc =
  3. if b < a then acc else aux a (b - 1) (b :: acc) in
  4. aux a b []
  5. let digit_sum n =
  6. let rec aux n sum =
  7. if n = 0 then sum else aux (n / 10) (sum + n mod 10) in
  8. aux n 0
  9. let count xs x = List.length (List.filter ((=) x) xs)
  10. let () =
  11. let dss, udss = List.map digit_sum (range 0 9999), range 0 36 in
  12. List.iter2 (Printf.printf "%d\t%d\n") udss (List.map (count dss) udss)
Success #stdin #stdout 0s 4400KB
stdin
Standard input is empty
stdout
0	1
1	4
2	10
3	20
4	35
5	56
6	84
7	120
8	165
9	220
10	282
11	348
12	415
13	480
14	540
15	592
16	633
17	660
18	670
19	660
20	633
21	592
22	540
23	480
24	415
25	348
26	282
27	220
28	165
29	120
30	84
31	56
32	35
33	20
34	10
35	4
36	1