Skip to content

Instantly share code, notes, and snippets.

@bradwright
Forked from andyhd/gist:595058
Created September 24, 2010 08:57
Show Gist options
  • Save bradwright/595081 to your computer and use it in GitHub Desktop.
Save bradwright/595081 to your computer and use it in GitHub Desktop.
# a heavy int is one where the average of the digits is greater than 7
# eg: 8678 is heavy because (8 + 6 + 7 + 8) / 4 = 7.25
# 8677 is not heavy because ( 8 + 6 + 7 + 7) / 4 = 7
def is_heavy(my_number, heaviness=7):
# cast @my_number to a string so we can iterate over it, then create a list of
# numbers greater than @heaviness. if this list length is greater to or equal than half
# the length of the original list, it's heavy
return len([i for i in str(my_number) if int(i) > heaviness]) >= (len(str(my_number)) / 2)
@rozza
Copy link

rozza commented Sep 24, 2010

def is_heavy(my_number, heaviness=7):
    # map each digit in @my_number to a string so sum them and then get the
    # average and determine if its greater than @heaviness number
    return sum(map(float, str(my_number))) / len(str(my_number)) > heaviness

@bradwright
Copy link
Author

Very good. Hunter wrote basically the same: http://gist.github.com/595089

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment