Last active
December 12, 2015 01:58
Revisions
-
mrdmnd renamed this gist
Feb 2, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mrdmnd created this gist
Feb 2, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ import string # Algorithm for SMBC #2874 - the "fouriest" transform. # Support bases 2-36. BASE_LIST = string.digits + string.letters def encode(integer, base): # Stolen off the internet from somewhere, # almost certainly guaranteed to be buggy. base_list = BASE_LIST[:base] ret = '' while integer != 0: ret = base_list[integer % base] + ret integer /= base return ret def transform(inp): # inp (integer) - A base-10 encoded integer to be transformed. # Returns (best_string, best_base) tuple. inp_str = str(inp) best_base = '10' best_string = inp_str max_num_fours = inp_str.count('4') for i in range(5, len(BASE_LIST)): # No base less than 5 will contain any '4' characters. tmp = encode(inp, i) cnt = tmp.count('4') if cnt > max_num_fours: max_num_fours = cnt best_base = str(i) best_string = tmp return best_string, best_base # Usage: # fouriest.transform(624) # ('4444', '5')