Pergunta de entrevista da empresa Bending Spoons

Logical reasoning test, programming exercise.