Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Unclear 8 lines proc solution in Creative category for Calculator-II by CDG.Axel
def calculator(log: str) -> str:
second, screen, save, op, magic = 0, 0, False, '=', lambda: (screen, -screen)[op == '-']
for key in log:
screen = second + magic() if key in '+-' and op != '=' and save else \
screen * 10 * save + int(key) if key.isdigit() else \
screen + second if key == '=' == op else \
(screen, second)[save] + (second := magic()) if key == '=' else screen
second, op = (second, screen)[key in '+-'], (key, op)[save := key.isdigit()]
return str(screen)
Feb. 21, 2023
Comments: