Well, here is my submission.. I truly was stuck with this so I just done
the most basic stuff, I will have a look through the other submissions a
bit later to see how others done it..
#!/usr/bin/ruby -w
argv = Array.new
if ARGV.empty?
puts "#{$0} <Postfix equation>"
else
ARGV.each do |a|
if ['+', '-', '/', '*'].include?(a)
last = argv.pop
first = argv.pop
argv << "(#{first} #{a} #{last})"
else
argv << a
end
end
puts argv
end
I will try and mod the code to remove some parenthesis.
Regards,
Lee
--
Posted via http://www.ruby-forum.com/.