Created
October 9, 2023 15:10
-
-
Save francorbacho/f126f2406d46ef4eb24d4cf9015d0621 to your computer and use it in GitHub Desktop.
Fortran Compiler Shenanigans
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
#!/usr/bin/python | |
# source: | |
# https://social.noyu.me/@hikari/statuses/01H0DQEAR01XPSH2EQCN2TH2S1 | |
def do_shenanigan(expression): | |
mappings = { | |
'+': '))+((', | |
'-': '))-((', | |
'*': ')*(', | |
'/': ')/(', | |
} | |
for key, alt in mappings.items(): | |
expression = expression.replace(key, alt) | |
return '((' + expression + '))' | |
if __name__ == '__main__': | |
original_expression = input() | |
expanded_expression = do_shenanigan(original_expression) | |
print(f"{original_expression} = {expanded_expression} = {eval(expanded_expression)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment