Skip to content

Instantly share code, notes, and snippets.

@TheZoom110
Last active March 4, 2025 11:20
Show Gist options
  • Save TheZoom110/2fbb7cd2cf21c3e71051d9e83835769c to your computer and use it in GitHub Desktop.
Save TheZoom110/2fbb7cd2cf21c3e71051d9e83835769c to your computer and use it in GitHub Desktop.
FLAMES using string slicing (Python)
# Copied from https://github.com/TheZoom110/fun-projects/blob/main/flames.py
def flames(name1: str, name2: str) -> str:
# Convert strings to a standard format
a = list(name1.upper())
b = list(name2.upper())
# While iterating over a,
# Removing i'th element from it will cause the i+1'th element to take its place
# In next iteration, i+2'th element, now in i+1'th index, will be be operated against
# Thus, i+1'th element will be skipped
# To avoid that, create a temporary copy of a to iterate over
for i in list(a):
if i in b:
a.remove(i)
b.remove(i)
n = len(a) + len(b)
f = "FLAMES"
f_len = 6
while f_len > 1:
r = n % f_len
if r == 0:
# Remove last element
f = f[: f_len - 1]
f_len -= 1
else:
# Remove r-1'th letter; start from r'th letter next
f = f[r:] + f[: r - 1]
f_len -= 1
return f[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment