Skip to content

Instantly share code, notes, and snippets.

@buzibu
Created June 2, 2015 18:56
Show Gist options
  • Save buzibu/06b0d056d6d2e03c9058 to your computer and use it in GitHub Desktop.
Save buzibu/06b0d056d6d2e03c9058 to your computer and use it in GitHub Desktop.
Aлгоритми
# Is_Palindrome(String)-> Boolean
# Checks if a text is palindrome or not (True ot False)
def Is_Palindrome(input_string):
string_len=len(input_string)
if string_len% 2 == 0:
beginning=input_string[:string_len/2]
ending=input_string[string_len/2:]
else:
beginning=input_string[:(string_len-1)/2]
ending=input_string[(string_len-1)/2+1:]
if beginning==ending[::-1]:
return True
else:
return False
# String_rotation(String, Integer)-> String
# Makes string rotation at given position
def String_rotation(My_string, position):
return My_string[position:]+My_string[:position]
def main_function(main_string):
palindrome_found=False
for i in range(len(main_string)):
current_rotation=String_rotation(main_string,i)
if Is_Palindrome(current_rotation):
print(current_rotation)
palindrome_found=True
if not palindrome_found:
print('NONE')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment