From: Ken Bloom Date: 2007-12-03T03:40:01+09:00 Subject: Re: [QUIZ] Postfix to Infix (#148) On Sun, 02 Dec 2007 12:14:10 -0500, Pawel Radecki wrote: > Hello everybody, > > Here's my solution. I know it's pretty long but I'm still learning... > BIG thanks for the quiz! > > > > #!/usr/bin/env ruby > > # Solution to Ruby Quiz #148 (see http://www.rubyquiz.com/quiz148.html) > # by Pawel Radecki (pawel.j.radecki@gmail.com). > > # Note1: There may be couple of different and correct postfix to infix # > transformations but this program only gives one and ignores others. # > # Example: > # postfix: 1 2 + 4 * 5 + 3 - > # infix: (1 + 2) * 4 + 5 - 3 > # infix: (1+2)*4+5-3 > # infix: 5 + (1 + 2) * 4 - 3 > # infix: 5 + 4 * (1 + 2) - 3 > # ... (there are more) > > # Note2: Unary operators not supported! > > # Note3: I don't know why ^ in input argument doesn't work, anybody > knows...? It appears to be this regex over here. You need to escape the ^ if you want to use it in a regex, because ^ signals the beginning of a line in a regex. > @string =~ > /([0-9\.]+|[a-z]+)\s([0-9\.]+|[a-z]+)\s((\*\*)|(V)|\+|\*|\/|-)/ --Ken -- Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/