------art_11735_1853889.1196650050878
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Solution to quiz #148.
Thanks,

-Dave
---------- Forwarded message ----------
From: Dave Pederson <dave.pederson.ruby / gmail.com>
Date: Nov 30, 2007 7:26 PM
Subject: Ruby Quiz #148
To: dave.pederson.ruby / gmail.com


#!/usr/bin/env ruby

op  w{ + - / * }
pm  w{ + - }

postfixes  "2 3 5 + *",
             "1 56 35 + 16 9 - / +",
             "56 34 213.7 + * 678 -",
             "5 9 * 8 7 4 6 + * 2 1 3 * + * + *"]

puts
postfixes.each do |postfix|
  stack  ]
  postfix.split.each do |c|
    if op.include?(c)
      second, first  tack.pop, stack.pop
      if pm.include?(c)
        stack.push "(#{first} #{c} #{second})"
      else
        stack.push "#{first} #{c} #{second}"
      end
    else
      stack.push(c)
    end
  end
  infix  tack.pop
  if (infix[0] 40 && infix[infix.size-1] 41)
    infix  nfix[1, infix.size-2]
  end
  puts "postfix  {postfix}"
  puts "infix  {infix}"
  puts
end

------art_11735_1853889.1196650050878--