Last active
March 24, 2021 12:12
-
-
Save prdoyle/e6c88f6c25e6c965b4633401d85f7c50 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
#! /usr/bin/python | |
from math import prod | |
def compute_digits( n ): | |
if n <= 9: | |
return [ n ] | |
else: | |
return compute_digits( n // 10 ) + [ n % 10 ] | |
def is_robust( value ): | |
digits = compute_digits( value ) | |
s = sum( digits ) | |
if s % len( digits ) != 0: | |
return False | |
avg = s / len( digits ) | |
lo = min( digits ) | |
hi = max( digits ) | |
if lo == 0 or lo == hi: | |
return False | |
things_to_try = digits + [ avg, lo, hi, hi-lo, len( digits ), s, prod( digits ) ] | |
badness = [ True for denominator in things_to_try if value % denominator != 0 ] | |
return not badness | |
for n in range( 1, 9999999 ): | |
if is_robust( n ): | |
print( n ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment