Skip to content

Instantly share code, notes, and snippets.

@marekyggdrasil
Created March 13, 2024 09:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marekyggdrasil/4ab75e035aa0cf809b50eb150b1ce21d to your computer and use it in GitHub Desktop.
Save marekyggdrasil/4ab75e035aa0cf809b50eb150b1ce21d to your computer and use it in GitHub Desktop.
Computing the bong-bing-bang-and-gong number for https://x.com/botnetzprovider/status/1767680709726978051?s=20
def numberToBase(n, b):
if n == 0:
return [0]
digits = []
while n:
digits.append(int(n % b))
n //= b
return digits[::-1]
def binary_to_decimal(binary_list):
decimal = 0
for digit in binary_list:
decimal = decimal * 2 + int(digit)
return decimal
def split_into_chunks(lst, chunk_size):
chunks = []
for i in range(0, len(lst), chunk_size):
chunks.append(lst[i:i + chunk_size])
return chunks
def convert(N, mids, finishes):
words = [m + f for m in mids for f in finishes]
space = len(words)
l = len(numberToBase(space, 2))
if 2**l > space:
l -= 1
converted = numberToBase(N, 2)
chunks = split_into_chunks(converted, l)
numbers = [binary_to_decimal(chunk) for chunk in chunks]
word = ''
for n in numbers:
word += words[n]
return word
vowels = ['a', 'i', 'u', 'e', 'o']
cons = ['n', 'g', 'm', 'k', 'j', 'sh', 'ch']
mids = [c + v for v in vowels for c in cons]
finishes = ['bong', 'bing', 'bang', 'gong']
n = 115116101112101100105116100105115099111118101114104111114114111114114101112111114116108097121101114105110115105100101119097108107104105108108116097116116111111109101116104111100104097112112121
word = convert(n, mids, finishes)
print(str(n).zfill(4), word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment