Skip to content

Instantly share code, notes, and snippets.

@kaspermunch
Created May 19, 2023 09:04
Show Gist options
  • Save kaspermunch/b99971c7f820ef7df3683859f3c8c1b6 to your computer and use it in GitHub Desktop.
Save kaspermunch/b99971c7f820ef7df3683859f3c8c1b6 to your computer and use it in GitHub Desktop.
Burrows+Wheeler transform
def burrows_wheeler_transform(text):
# Create a list of all rotations of the input text
rotations = [text[i:] + text[:i] for i in range(len(text))]
# Sort the list of rotations in lexicographic order
rotations.sort()
# Return the last characters of each rotated string, which is the
# Burrows-Wheeler transform of the input text
return “”.join([rot[-1] for rot in rotations])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment