Last active
June 12, 2018 19:56
-
-
Save matthewdeanmartin/8a86efbc981fff1deed08ce43719c55f 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
# This is not built in to python! | |
# https://stackoverflow.com/a/28825390/33264 | |
def digit_to_char(digit): | |
if digit < 10: | |
return str(digit) | |
return chr(ord('a') + digit - 10) | |
def str_base(number, base): | |
while number > 0: | |
number, digit = divmod(number, base) | |
yield digit_to_char(digit) | |
candidates = {} | |
target = 9999 | |
inital_fours = len([x for x in str(target) if x =="4"]) | |
for base in range(2,24): | |
candidate = "".join([x for x in str_base(target, base)]) | |
fouriness = len([x for x in candidate if x =="4"]) | |
if fouriness>0: | |
candidates[(candidate, base)] = fouriness | |
max_fours = max(candidates.values()) | |
for candidate, fours in candidates.items(): | |
if fours == max_fours: | |
print("{0} (base {1}) is fouriest".format(candidate[0], candidate[1])) | |
if fours > inital_fours: | |
print("{0} (base {1}) is fourier".format(candidate[0], candidate[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment