Created
September 22, 2022 00:54
-
-
Save shugo/03c1537cedebb78a08b3a42beaf4a65a to your computer and use it in GitHub Desktop.
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 evaluate(expr) | |
case expr | |
in ["value", x] | |
x | |
in ["+", x, y] | |
evaluate(x) + evaluate(y) | |
in ["-", x, y] | |
evaluate(x) - evaluate(y) | |
in ["*", x, y] | |
evaluate(x) * evaluate(y) | |
in ["/", x, y] | |
evaluate(x) / evaluate(y) | |
end | |
end | |
def answer20(expr) | |
evaluate(expr) | |
end | |
p answer20(["+", ["value", 1], ["*", ["value", 2], ["value", 3]]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment