Download benchmarks/quixbugs/python/rpn_eval.py from SevdanurGenc/LLM-Automated-Test-Generation-Agent: direct link, hf CLI and curl.
- Browser
- Download file 876 Bytes
-
https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/quixbugs/python/rpn_eval.py
- Command line
-
hf download hf://SevdanurGenc/LLM-Automated-Test-Generation-Agent/benchmarks/quixbugs/python/rpn_eval.py
-
curl -L -o rpn_eval.py https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/quixbugs/python/rpn_eval.py
876 Bytes
| def rpn_eval(tokens): | |
| def op(symbol, a, b): | |
| return { | |
| '+': lambda a, b: a + b, | |
| '-': lambda a, b: a - b, | |
| '*': lambda a, b: a * b, | |
| '/': lambda a, b: a / b | |
| }[symbol](a, b) | |
| stack = [] | |
| for token in tokens: | |
| if isinstance(token, float): | |
| stack.append(token) | |
| else: | |
| a = stack.pop() | |
| b = stack.pop() | |
| stack.append( | |
| op(token, b, a) | |
| ) | |
| return stack.pop() | |
| """ | |
| Reverse Polish Notation | |
| Four-function calculator with input given in Reverse Polish Notation (RPN). | |
| Input: | |
| A list of values and operators encoded as floats and strings | |
| Precondition: | |
| all( | |
| isinstance(token, float) or token in ('+', '-', '*', '/') for token in tokens | |
| ) | |
| Example: | |
| >>> rpn_eval([3.0, 5.0, '+', 2.0, '/']) | |
| 4.0 | |
| """ | |