Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 24 Online
OpenStudy (anonymous):

Does anyone have the solution for problem 4 and 5 of homework 4. The solutions on the website seem not match the problem of decryption.

thomaster (thomaster):

We don't give answers here. We can help you with your problem if the solution doesn't match, and see what you did wrong.

OpenStudy (anonymous):

post yours and we'll give you a hand - please use a code pasting site: - http://dpaste.com - http://pastebin.com - https://gist.github.com/ - http://pastie.org - http://codepad.org - http://ideone.com - http://www.repl.it/ but if you would prefer, i could post mine

OpenStudy (anonymous):

Thank you very much. My code worked well for the prob 4. But when using it to decrypt the prob 5, it went wrong at the 153th letter. At that start point I got a word 'an', but the real word may be 'boarded', and after that when decrypting the rest of the string, it failed to find a word. Is it because I start by setting the start position 0? I saw in the pseudocode said it should not be 0. This is my code, http://dpaste.com/1350013/

OpenStudy (anonymous):

after applying a shift, you look for the first 'word' (lines 390, 391, 392+) if that word is in the dictionary, - you assume that it is the correct shift for that position - you save the shift and the start position - you remove the word from the text - you return from the function - the return value is the saved (position, start) plus a recursion with the new text and the current start position that all looks good - what if two different shifts decode a word? - you pick the first shift that decodes a word - maybe that is not the best strategy - maybe you want to try all the shifts on the text and pick the Best one - I decided that the Best one was the one that produced the longest word. That is kind of arbitrary but for this problem it worked. When my code starts getting hard to follow - i can't see what my algorithm is doing. i break it up in chunks and write functions to do the 'busy work' - if i choose good names for those functions then it is easy to follow my algorithm. it also helps to use a small phrase that you know the answer to while debugging this is a good one ``` ## 'adeptly polkaed matriarch sixths breakage' ## [(0, 2), (8, 12), (16, 0), (26, 17), (33, 0)] s = 'cfgrvn bcbzyosrn ogewoeqvnwmaxlwdfvieoeki' ```

OpenStudy (anonymous):

Thank you. I think trying all the shifts and pick one may be a good idea. I will try that.

OpenStudy (anonymous):

Can you show me your code for the problem 4 and 5? I kind of stuck on that now.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!