Problem 006

Problem

Description

HP-35

Back in the day, when men where men and computers were the size of minivans and Charlie Weis was still rooming with Joe Montana, the pride and joy of every engineering geek was his HP scientific calculator. Even the mighty Woz [1] cherished his legendary HP-35.

Of course, since the old timers back then were super awesome (unlike today's young whippersnappers), they didn't use the standard lame infix notation to perform their calculations; instead, they used the uber 1337 reverse polish notation.

That is, rather than entering in <operand> <operation> <operand>, you would enter in <operand> <operand> <operation> to perform a calculation on the RPN calculator. Using RPN eliminates the need for paretheses and orders of operation since it is never ambiguous what operands are used with which operation; the operation is always applied to the previous arguments.

This means that if you wanted to perform 3 + 4, you would have to enter in:

3 4 +

To prove that you too are uber awesome and to relive some of the glory days, you are to create a RPN calulator that can perform: +, -, *, /, and ^. For the sake of nostalgia, you should output the results of the caluation as digital LED numbers as shown here:

*    _  _     _  _  _  _  _  _
*  | _| _||_||_ |_   ||_||_|| |
*  ||_  _|  | _||_|  ||_| _||_|
*

Each digit is composed of a combination of | and _ and occupies the same amount of space.

Input

Each line in the input will be a RPN expression that you have to calculate and output such as in this sample input:

4
5 8 * 1 +

Output

For each RPN expression, output the calculation as a LED number such as in this sample output:

|_|
  |

|_|  |
  |  |

Note

Use the input and output files, rather than copying and pasting since the problem requires absolute precision regarding the whitespace. Simply copying and pasting from the website will not yield an accurately formatted text file.

[1]Woz spilled my french fries. I will never forget.

Solution

Approach

Tokenize each input line. Push operands onto a stack and perform operations from items on top of the stack as specified. The final result is the top of the stack. Convert the value of the expression to the LED by building the output in a 3 row vector.

Input/Output

Source Code