Skip to content

Instantly share code, notes, and snippets.

@tommyli
tommyli / percentageBreakdown.groovy
Created December 17, 2012 00:41
Percentage Breakdown problem from @marsbomber
// Fun exercise with @marsbomber, his solution at https://gist.github.com/4291868
List<BigDecimal> percentageBreakdown(List<Integer> input) {
return pb(input, 1.0000)
}
List<BigDecimal> pb(List<Integer> input, BigDecimal remaining) {
if (input.empty) return []
def head = input.head()
if (head == 0) return [0] + pb(input.tail(), remaining)