The Monthly Course: Infix to RPN


The program will be given a mathematical expression written in traditional infix notation, and has to convert it to reverse polish notation (RPN).


The program is a filter: it must read from STDIN, and send output to STDOUT.


The tiebreaker will favour programs with short lines and lots of characters matching /[ \t\d*\/+()-]/.

General rules


  Input                 Example output
  1 + 1                 1 1 +
  2*2 + 3*3             2 2 * 3 3 * +
  2*(2 + -3)*3          2 2 -3 + * 3 * 
Note that there are multiple valid solutions to most inputs.


The game starts September 1st (05:00 UTC) and ends September 8th (05:00 UTC).

Test program

A test program [version 8] is provided to help screen entries.

Any program that passes the test program should be submitted. If you are surprised that your solution passed the test program, please submit it anyway! That will help us identify bugs in the test program.

Name your script, and place it in the same directory as your test program. Then verify and score your attempt using:

    $ perl

The test program is based on Ton Hospel's generic golf tester, and thus has plenty of useful features. For more information on them type:

    $ perl --help

Passing the test program does not assure your solution is valid. The referees have the final say.


You can submit your solutions here (you'll notice it's the same page as the Leaderboard). As a courtesy to other players, you should not wait until the last moment to submit your solutions. Everyone has more fun when the leaderboard depicts the situation correctly.

Do not publish your solutions anywhere. That will spoil the game, as your solutions are meant to be secret. All solutions will be published at the end of the game.

Prizes (provided by O'Reilly and ActiveState) will be awarded to veteran and beginner winners. A prize may also be awarded to any especially interesting artistic and/or unorthodox solutions.


You can track your ranking through the leaderboard here. Beginners are encouraged to enter and there is a separate leaderboard for them.

There is also a special leaderboard for teams. There will be no prizes awarded to the best team, other than the admiration of your fellow golfers. If you are in a team, you can't also play individually.


We encourage you to send feedback as well as your ideas for future holes and tiebreakers to


If you want to be a referee next month, drop us a note: