Skip to content

Instantly share code, notes, and snippets.

@dzfl
Created June 10, 2010 17:15
Show Gist options
  • Save dzfl/433314 to your computer and use it in GitHub Desktop.
Save dzfl/433314 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
while $_ = gets
a ||= []
if /\d/ ~= $_
a << $_.to_i
end
if /([-+*\/])/ ~= $_
a << eval([a.pop, a.pop].reverse.join($1)
puts a[-1]
end
end
# klm is cool
# ruby -ne'a||=[];~/\d/&&a<<$_.to_i;~/([-+*\/])/&&a<<eval([a.pop,a.pop].reverse.join $1)and puts a[-1]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment