First solution for the exercise, with only a simple encoder.