Created
September 18, 2020 16:19
-
-
Save erikseulean/cb00262371aaad3c3fe058e49eb37c30 to your computer and use it in GitHub Desktop.
Untangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sequence=""" | |
SRSRRSSRSRSSRSSRRSSRSSSSSRSSRSSRSRSSRSSRSSSSSSSSRSSRSSSSSRSSRSSRRSSRSSSSSRSSRSSRSSSSSSSSSSSSSSSSSRSSRSSRS | |
""" | |
from fractions import Fraction | |
def decode(seq): | |
x = 0 | |
for nr in seq: | |
if nr == 'S': | |
if x == "inf": | |
print(x) | |
continue | |
x = x + 1 | |
elif nr == "R": | |
if x == "inf": | |
x = 0 | |
elif x == 0: | |
x = "inf" | |
else: | |
x = 0 - Fraction(1, x) | |
print(x) | |
return x | |
pq = decode(sequence) | |
res = [] | |
while pq != 0: | |
if pq < 0: | |
res.append("S") | |
pq = pq + 1 | |
else: | |
pq = 0 - Fraction(1, pq) | |
res.append("R") | |
print("".join(res)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment