re: Daily Coding Puzzles - Oct 29th - Nov 2nd VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Thursday Calculating with Functions: This time we want to write calculations using functions and get the results. For example: seven(times(five...
 

Ruby cheat.

substs =
  %w|zero one two three four five six seven eight nine|.
    each_with_index.to_h.merge(
      ")" => "", "(" => "", "times" => "*",
      "plus" => "+", "minus" => "-", "div" => "/")
eval 'seven(times(five()))'.gsub(Regexp.union(substs.keys), substs)
#⇒ 35


code of conduct - report abuse