-
-
Save bradwright/595081 to your computer and use it in GitHub Desktop.
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
# 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
commented
Sep 24, 2010
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