Skip to content

Instantly share code, notes, and snippets.

@ZakriaJanjua
Created June 17, 2022 20:50
Show Gist options
  • Save ZakriaJanjua/1cf533e5321ee7e1fb0249d93bd3d1dc to your computer and use it in GitHub Desktop.
Save ZakriaJanjua/1cf533e5321ee7e1fb0249d93bd3d1dc to your computer and use it in GitHub Desktop.
Input an integer in the function and it will give you the equivalent alphabet of it. The alphabets starts appending after 26
# 26 Z
# 27 AA
# 80 CB
# 702 ZZ
# 728 AAZ
# 705 AAC
# 13456 SWN
# 456977 YYZA
import math
def is_factor(int_input, dictionary):
remainders = []
while int_input >= 26:
quotient = math.floor(int_input / 26)
remainder = int_input % 26
if remainder == 0:
remainders.append(26)
quotient -= 1
else:
remainders.append(remainder)
int_input = quotient
if quotient != 0:
remainders.append(quotient)
result = "".join(dictionary[x] for x in remainders[::-1])
return result
def not_factor(int_input, dictionary):
remainders = []
new_input = int_input
while new_input > 26:
quotient = math.floor(new_input / 26)
remainder = new_input % 26
remainders.append(remainder)
new_input = quotient
remainders.append(new_input)
result = "".join([dictionary[x] for x in remainders[::-1]])
return result
def findEquivalent(int_input):
dictionary = {
1: "A",
2: "B",
3: "C",
4: "D",
5: "E",
6: "F",
7: "G",
8: "H",
9: "I",
10: "J",
11: "K",
12: "L",
13: "M",
14: "N",
15: "O",
16: "P",
17: "Q",
18: "R",
19: "S",
20: "T",
21: "U",
22: "V",
23: "W",
24: "X",
25: "Y",
26: "Z",
}
factor = False
quotient = int_input
while quotient >= 26:
if quotient % 26 == 0:
factor = True
break
quotient = math.floor(quotient / 26)
if factor == False:
return not_factor(int_input, dictionary)
else:
return is_factor(int_input, dictionary)
print(findEquivalent(456977))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment