Bending Spoons Interview Question

Logical reasoning test, programming exercise.