Skip to content

Instantly share code, notes, and snippets.

@jfelipe
Created October 21, 2015 01:47
Show Gist options
  • Save jfelipe/1dcced6ad25d7875ee28 to your computer and use it in GitHub Desktop.
Save jfelipe/1dcced6ad25d7875ee28 to your computer and use it in GitHub Desktop.
def moving_shift(s, shift):
final_result = [""] * 5
result = ""
counter = shift
for letter in s:
if letter.isalpha():
pombo = ord(letter) + counter - limit(letter)
base = ord('z') - ord('a') + 1
new_letter = (pombo % base) + limit(letter)
result += str(chr(int(new_letter)))
else:
result += str(letter)
counter += 1
my_array = transform_array(result)
i = 0
words_array = result.split()
for idx, val in enumerate(my_array):
words_num = my_array[idx]
temp_array = [""] * words_num
y = 0
while words_num > 0:
temp_array[y] = words_array[i]
words_num -= 1
y += 1
i += 1
final_result[idx] = " ".join(temp_array)
return final_result
def demoving_shift(s, shift):
string = "".join(s)
result = ""
counter = shift
for letter in string:
if letter.isalpha():
pombo = ord(letter) - counter - limit(letter)
base = ord('z') - ord('a') + 1
new_letter = (pombo % base) + limit(letter)
result += str(chr(int(new_letter)))
else:
result += str(letter)
counter += 1
return result
def limit(letter):
if letter.isupper():
return ord('A')
else:
return ord('a')
def transform_array(a):
count = len(a.split())
zombo = count / 4
my_array = [0] * 5
if count % 5 == 0:
my_array = [count/5] * 5
else:
mod = count % 4
suma_total = 0
for idx, val in enumerate(my_array):
if suma_total + 1 < count:
my_array[idx] = zombo
suma_total += zombo
if mod != 0:
if my_array[4] == 0:
my_array[4] = mod
else:
i = 0
while mod > 0 and suma_total < count:
my_array[i] += 1
mod -= 1
i += 1
suma_total += 1
if my_array[4] != 0 and my_array[3] - my_array[4] >= 2:
my_array[3] -= 1
my_array[4] += 1
return my_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment