Playing around with algorithms in Groovy