Last active
October 26, 2017 02:34
-
-
Save AaronFlower/658bcc450a16f3178fbb2c4a0c4f9b83 to your computer and use it in GitHub Desktop.
Programming Pearls: Column 2, vector-rotation
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
def vector_rotation(str, pos): | |
'''Transpose concept: (A.T B.T).T = (BA) ''' | |
l_half = str[:pos][::-1] | |
r_half = str[pos:][::-1] | |
new_str = l_half + r_half | |
return new_str[::-1] | |
s = 'abcdefgh' | |
print(vector_rotation(s, 2)) | |
print(vector_rotation(s, 3)) | |
print(vector_rotation(s, 7)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment