let range a b =
let rec aux a b acc =
if b < a then acc else aux a (b - 1) (b :: acc) in
aux a b []
let digit_sum n =
let rec aux n sum =
if n = 0 then sum else aux (n / 10) (sum + n mod 10) in
aux n 0
let count xs x
= List.length
(List.filter
((=) x
) xs
) let () =
let dss, udss
= List.map digit_sum
(range
0 9999), range
0 36 in List.iter2
(Printf.printf
"%d\t%d\n") udss
(List.map
(count dss
) udss
)
bGV0IHJhbmdlIGEgYiA9IAogIGxldCByZWMgYXV4IGEgYiBhY2MgPSAKICAgIGlmIGIgPCBhIHRoZW4gYWNjIGVsc2UgYXV4IGEgKGIgLSAxKSAoYiA6OiBhY2MpIGluICAKICBhdXggYSBiIFtdCmxldCBkaWdpdF9zdW0gbiA9IAogIGxldCByZWMgYXV4IG4gc3VtID0gCiAgICBpZiBuID0gMCB0aGVuIHN1bSBlbHNlIGF1eCAobiAvIDEwKSAoc3VtICsgbiBtb2QgMTApIGluCiAgYXV4IG4gMApsZXQgY291bnQgeHMgeCA9IExpc3QubGVuZ3RoIChMaXN0LmZpbHRlciAoKD0pIHgpIHhzKQpsZXQgKCkgPSAKICBsZXQgZHNzLCB1ZHNzID0gTGlzdC5tYXAgZGlnaXRfc3VtIChyYW5nZSAwIDk5OTkpLCByYW5nZSAwIDM2IGluCiAgTGlzdC5pdGVyMiAoUHJpbnRmLnByaW50ZiAiJWRcdCVkXG4iKSB1ZHNzIChMaXN0Lm1hcCAoY291bnQgZHNzKSB1ZHNzKQ==