The Monthly Course: Infix to RPN


Goal

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


Specification

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


Tiebreaker

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


General rules


Examples

  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.

Deadline

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 rpn.pl, and place it in the same directory as your test program. Then verify and score your attempt using:

    $ perl tpr05a.pl

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 tpr05a.pl --help

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


Submitting

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.


Leaderboard

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.


Feedback

We encourage you to send feedback as well as your ideas for future holes and tiebreakers to golf@theperlreview.com.


Referees

If you want to be a referee next month, drop us a note: golf@theperlreview.com