Last active
August 29, 2015 14:01
-
-
Save urokuta/5a6470a1ae9c4274b855 to your computer and use it in GitHub Desktop.
simple_calc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def expr(e) e.to_s.include?("=") ? e.split[0..-2].inject([]){|arr,e| (!arr.empty? && arr.last =~ /[^\d]/) ? [eval([*arr,e].join)] : arr << e } : ->(_e){expr("#{e} #{_e}")} end | |
puts expr(4)["+"][3]["*"][2]["-"][1]["="] |
Author
urokuta
commented
May 10, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment