Skip to content

Instantly share code, notes, and snippets.

@JanneSalokoski
Created April 26, 2016 06:29
Show Gist options
  • Save JanneSalokoski/2c4e6ab4a47daeaf9880f65064389c77 to your computer and use it in GitHub Desktop.
Save JanneSalokoski/2c4e6ab4a47daeaf9880f65064389c77 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import math
debug = False # Whether debug output should be printed
def get_input():
"""Parse for user given numbers from arguments,
if none are found, prompt user for numbers."""
args = sys.argv[1:]
if len(args) == 0:
num = input("> ")
#print() # A newline after input
else:
num = args[0]
return int(num)
def get_index(chars, char):
for i in range(0, len(chars)):
if chars[i] == char: print("'{0}' is number {1}".format(char, i))
def main():
chars = ["0", "1", "2", "3", "4",
"5", "6", "7", "8", "9",
"a", "b", "c", "d", "e",
"f", "g", "h", "i", "j",
"k", "l", "m", "n", "o",
"p", "q", "r", "s", "t",
"u", "v", "w", "x", "y",
"z", "A", "B", "C", "D",
"E", "F", "G", "H", "I",
"J", "K", "L", "M", "N",
"O", "P", "Q", "R", "S",
"T", "U", "V", "W", "X",
"Y", "Z", "+", "-"]
# Standard would use '/' in favour of '-',
# which is not great for unix filepaths.
bits = len(chars)
if debug: print("Using {0} bits".format(bits))
num = get_input()
#char_amount = math.floor(num / bits) + 1
#if debug: print("Characters needed: {0}".format(char_amount))
#print("{0}*64+{1}*1={2}+{3}={4} => {5}{6}".format(math.floor(num / bits), num % bits, math.floor(num / bits) * 64, num % bits, (math.floor(num / bits) * 64) + (num % bits), chars[math.floor(num / bits)], chars[num % bits]))
for x in range(0, 64):
for y in range(0, 64):
for z in range(0, 64):
if num == 64**2*x+64**1*y+64**0*z: print("64²·{0} + 64¹·{1} + 64⁰·{2} = {3} → {4}{5}{6}".format(x, y, z, num, chars[x], chars[y], chars[z]))
#get_index(chars, "b")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment