encode needs group
9th solution

Not very smart, but I could get my head around a solution using fold*