Skip to content

Instantly share code, notes, and snippets.

@francorbacho
Created October 9, 2023 15:10
Show Gist options
  • Save francorbacho/f126f2406d46ef4eb24d4cf9015d0621 to your computer and use it in GitHub Desktop.
Save francorbacho/f126f2406d46ef4eb24d4cf9015d0621 to your computer and use it in GitHub Desktop.
Fortran Compiler Shenanigans
#!/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