Finite state transducer solution.

Although it is not a programming language, and may break some rules, the solution is still interesting.