/prefix_notation

Coding exercise

Primary LanguageRuby

Write a program to evaluate a prefix notation string. Input operators + * - /. Numbers are all positive integers only.

Example:

  • "9" => 9
  • "+ 1 2" => 3 (1 + 2)
  • "+ + 1 2 30" => 33 ((1+2)+30)
  • "+ + 12 16 * 10 4" => 68 ((12+16)+(10*4))