Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
n % 6 == 4 solution in Creative category for Collatz Ztalloc by veky
def collatz_convert(data: int | str) -> int | str | None:
updown, n = [], 1
if isinstance(data, int):
while data != 1:
updown.append('du'[data % 2])
data = data * 3 + 1 if data % 2 else data // 2
return ''.join(updown)
elif isinstance(data, str):
for direction in reversed(data):
if direction == 'd': n *= 2
elif direction == 'u' and n%6 == 4 and n > 4: n = (n-1)//3
else: return
return n
March 28, 2024
Comments: