anonymous
  • anonymous
I'm trying to complete problem set 4 and the find_best_shifts_rec function. It works for the most part, but for some reason, it is unable to completely decode the fable. One of the recursive calls fails at the same spot in the fable. Any help would be appreciated Here is my code: def find_best_shifts_rec(wordlist, text, start): for shift in range(27): s = text[:start] + apply_shift(text[start:], shift) space = s.find(" ", start) if space > 0 and is_word(wordlist, s[start:space]): return [(start, shift)] + find_best_shifts_rec(wordlist, s, space + 1) if space < 0 and is_word(wordlist, s[start:]): return [(start, shift)] if space < 0 and not is_word(wordlist, s[start:]): continue
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
No comment on whether this'll solve anything (I'm actually trying to figure out how to do this question myself), but shouldn't space be <= 0?
anonymous
  • anonymous
Well, I thought about putting that in there. But then I realized: space = s.find(" ", start) the above variable actually holds an index to where the space is found. So if a space is found at index 0, the text won't be a word, and so the three 'if' statements should evaluate to false in order to move onto the next shift (or integer in the for loop). Thanks for the help though.
rsmith6559
  • rsmith6559
If you know where in the fable the program is failing, manually step through your code with the data that it's working with at the time.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Thanks, it looks like the function is finding a shift that creates a word, but it's the wrong shift. Back to the drawing board.

Looking for something else?

Not the answer you are looking for? Search for more explanations.