Skip to content

Instantly share code, notes, and snippets.

@alexander-n8hgeg5e
Created December 15, 2023 15:22
Show Gist options
  • Save alexander-n8hgeg5e/29d27fecf7f78ec7fc7c0cc589b82b25 to your computer and use it in GitHub Desktop.
Save alexander-n8hgeg5e/29d27fecf7f78ec7fc7c0cc589b82b25 to your computer and use it in GitHub Desktop.
golden ratio
#!/usr/bin/env python3
def is_more_golden_than( a, b , gs=1):
goldstandard = gs
ao=a
bo=b
# TODO: use math to refactor the next 6 lines
a = a / goldstandard
b = b / goldstandard
wa = a if a < 1 else -1/a
wb = b if b < 1 else -1/b
wa = abs(abs(wa)-1)
wb = abs(abs(wb)-1)
judgement = True if wa < wb else False
print(f'{ao:>5.3} vs {bo:<5.3} > {wa:+.3f}, {wb:+.3f} golden = {gs:0.2f} {judgement}' )
return judgement
is_more_golden_than(1.5 , 0.66666 , gs=1 )
is_more_golden_than(2.0 , 2.1 , gs=2 )
is_more_golden_than(1.9 , 2.0 , gs=2 )
is_more_golden_than(1.9 , 2.1 , gs=2 )
is_more_golden_than(0.25, 0.75 , gs=0.5)
# output:
# 1.5 vs 0.667 > +0.333, +0.333 golden = 1.00 True
# 2.0 vs 2.1 > +0.000, +0.048 golden = 2.00 True
# 1.9 vs 2.0 > +0.050, +0.000 golden = 2.00 False
# 1.9 vs 2.1 > +0.050, +0.048 golden = 2.00 False
# 0.25 vs 0.75 > +0.500, +0.333 golden = 0.50 False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment