Skip to content

Instantly share code, notes, and snippets.

@aliou
Last active December 15, 2015 19:09
Show Gist options
  • Save aliou/5309178 to your computer and use it in GitHub Desktop.
Save aliou/5309178 to your computer and use it in GitHub Desktop.
(* val map_reduce : int list -> int list list = <fun> *)
let map_reduce lst =
let rec partition acc = function
| 0 -> acc
| x -> partition ((x mod 10) :: acc) (x / 10)
in let rec map acc = function
| [] -> List.rev acc
| h :: tl ->
if h > 10 then map ((partition [] h) :: acc) tl
else map ((h :: [] ) :: acc) tl
in map [] lst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment