【发布时间】:2015-03-31 23:51:10
【问题描述】:
我正忙于通过麻省理工学院的开放课件论文,并且有点卡在某个问题上。
问题涉及通过在文本中的不同点多次移动来解决具有多级加密的凯撒密码。
我编写的代码解决了这些移位问题,并返回了解密凯撒移位文本所需的位置和移位编号。
该函数应返回一个包含班次开始位置和班次编号的元组列表。目前我得到的只是以下内容:
(([12, 11], [3, 9]), [0, 21])
任何帮助将不胜感激。
def find_best_shifts_rec(wordlist, text, start)
for shift in xrange(27):
## Begin shifting the text along the segments you would like to see shifted while holding constant the text that is not to change.
s = text[:start] + apply_shift(text[start:],shift)
print s
letter_position = start
for letter in s[start:]:
if letter == " " and is_word(wordlist,s[start:letter_position]):
start = letter_position + 1
letter_position += 1
if is_word(wordlist,s[start:len(s)]):
print "Base Case"
shifts += (begin,shift)
return shifts
elif start != begin:
print "Recursion"
shifts += (begin,shift)
return find_best_shifts_rec(wordlist,s,start), shifts
【问题讨论】:
标签: python list recursion tuples