Created
August 29, 2018 21:28
Star
You must be signed in to star a gist
Print the number of zeros for the years from 0 to 128 in the number systems from base 2 to base 128. Guess which Birthday has the most zeros!
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
import math | |
# Definition | |
class YearZeros: | |
year = 0 | |
zeros = 0 | |
base = set() # Store the year inf form of 'all' (2 to 128) bases here. E.g. year 4 would be | |
# Declaration | |
result = [] | |
# Number characters | |
characters = [u"0",u"1",u"2",u"3",u"4",u"5",u"6",u"7",u"8",u"9",u"a",u"b",u"c",u"d",u"e",u"f",u"g",u"h",u"i",u"j",u"k",u"l",u"m",u"n",u"o",u"p",u"q",u"r",u"s",u"t",u"u",u"v",u"w",u"x",u"y",u"z",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600",u"\U0001F600"] | |
def getNumber(decimalNumber, base, characters): | |
remainder = -1 | |
denominator = decimalNumber | |
goOn = True | |
result = u"" | |
while goOn: | |
remainder = denominator % base | |
denominator = int(math.floor(denominator / base)) | |
result = characters[remainder] + result | |
if denominator == 0: | |
goOn = False | |
#print u"From: " + str(decimalNumber).encode('utf-8') + u" to: " + str(result).encode('utf-8') | |
return result | |
#getNumber(5, 2, characters) | |
#getNumber(20, 10, characters) | |
#getNumber(20, 16, characters) | |
#getNumber(40, 56, characters) | |
# Initialize | |
for year in range(0, 129): | |
#print year | |
result.append(YearZeros()) | |
result[year].year = year | |
result[year].base = [] | |
# Represent the year in all bases and store it in the base array as a string. | |
for base in range (2, 129): | |
for year in range (0, 129): | |
result[year].base.append(getNumber(year, base, characters)) | |
# Sum zeros | |
for year in range(0, 129): | |
for base in range (0, 127): | |
for char in result[year].base[base]: | |
if char == u"0": | |
result[year].zeros += 1 | |
# Print results | |
print "year;zeros;numbers" | |
for year in range(0, 129): | |
print str(year) + ";" + str(result[year].zeros) + ";" + str(result[year].base) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment