Groovy Cookbook

List of combinations from a list of lists in Groovy

Groovy has many useful functions built-in, and one of them is Iterable.combinations() that takes aggregated collections and finds all combinations of items. However, if we take a look its source code, we will find out that it was implemented using very imperative approach (nested for-loops + some if-statement). In this blog post I will show you how to implement the same function using Groovy and tail-recursion algorithm. Enjoy!

Read more →

Programming tips

Count frequency of a digit in a factorial of number using Haskell

Some time ago I was interviewed to one of the Java-based projects and I was asked to solve this pretty interesting puzzle. The question was "how to count frequency of a digit in a factorial of number, let’s say 1000". I tried to solve it using Java 8 Stream API, but I guess you see how bad decision it was. Problems like that can be easily solved with pure functional languages and today we are going to find out how to solve this puzzle with Haskell.

Read more →