4 kyu
Infix to Postfix Converter
1,134 of 2,675thepyr
Description:
Construct a function that, when given a string containing an expression in infix notation, will return an identical expression in postfix notation.
The operators used will be +
, -
, *
, /
, and ^
with left-associativity of all operators but ^
.
The precedence of the operators (most important to least) are : 1) parentheses, 2) exponentiation, 3) times/divide, 4) plus/minus.
The operands will be single-digit integers between 0 and 9, inclusive.
Parentheses may be included in the input, and are guaranteed to be in correct pairs.
to_postfix("2+7*5") # Should return "275*+"
to_postfix("3*3/(7+1)") # Should return "33*71+/"
to_postfix("5+(6-2)*9+3^(7-1)") # Should return "562-9*+371-^+"
to_postfix("1^2^3") # Should return "123^^"
You may read more about postfix notation, also called Reverse Polish notation, here: http://en.wikipedia.org/wiki/Reverse_Polish_notation
Mathematics
Algorithms
Similar Kata:
Stats:
Created | Jan 29, 2014 |
Published | Jan 29, 2014 |
Warriors Trained | 15587 |
Total Skips | 6691 |
Total Code Submissions | 15444 |
Total Times Completed | 2675 |
JavaScript Completions | 649 |
Python Completions | 1134 |
C++ Completions | 714 |
Ruby Completions | 68 |
Haskell Completions | 69 |
Rust Completions | 125 |
Total Stars | 513 |
% of votes with a positive feedback rating | 91% of 449 |
Total "Very Satisfied" Votes | 378 |
Total "Somewhat Satisfied" Votes | 61 |
Total "Not Satisfied" Votes | 10 |