Hi everyone, I cannot for the life of me figure out what I'm doing wrong with Problem 4 in pset4. It's driving me crazy. Here's the link to the troublesome part of my code: http://pastebin.com/Td5d7S1N I left a bunch of print statements in in case that helps. What happens is the first time it recurses (so, the second time through), n doesn't iterate through the string to find the next space; it remains stuck on the value of the last space. What the heck is going on here??? Thanks.
Never mind, I was miraculously finally able to figure it out. I was using index() wrong. Let this be a warning to all of you.
What the heck is going on here??? You're becoming experienced. Ain't it fun?
Hi Ricketybridge - I'm stuck on the same problem in PS4... Can you give me some tips on your overall concept? I'm looking at your code but haven't figured it out yet. Appreciate the help!
rsmith: ugh, yeah, about as fun as a root canal on a bumpy road. clint: I'm actually still having trouble with it, albeit on a different aspect than the one I posted about. The fact that the solution isn't for the right version of the problem set makes it especially infuriating. I had some difficulty myself in formulating the gist of the overall concept, even with the pseudocode. I started actually by ignoring their pseudocode and just sketching the things I DID know (like checking each successive letter for a space). That worked to an extent, but still had flaws, so at that point I went through the pseudocode carefully line by line and adjusted my code to conform to it exactly even though it didn't make much sense to me at the time. This worked better, but as I mentioned above, I'm still having issues. So my code isn't complete or correct, obviously, so I wouldn't model yours after it if I were you. (Although I actually just now realized through writing this comment what I'm missing, so I'll post my code if I finally get it to work.) But I think the main gist of it is getting slices of text from the "start point" to the next space or the end of the string, and when a shift on that slice returns a valid word, to run the function again, only the new start point is now the position right after the space after the valid word. Does that help, or is there something else about it that's confusing?
Ricketybridge: Okay after pounding my head against the table for a few hours I finally was able to develop a game plan and I have a partially working code. I didn't even see that pseudocode pdf until just recently... I need to go through and figure out what they're doing to help solve my code's problem. My code does as you said - it starts from the beginning of the text and chews through it until it finds a possible solution. Then it figures out where the next start point should be, it decodes the text up to our current point, and then it calls itself with the partially decoded text and the next starting point. My only problem is that my code isn't smart enough to catch a failure and backtrack... which I think is what the provided pseudocode goes over. If my code goes down the wrong path at some point, it ends up with gibberish. If you find a solution I'd love to take a look. I'll also post mine if I figure it out.
ah, I thought mine didn't catch a failure and backtrack either, and then I realized it did. :\ What happens is that after running through all 27 shifts, "start" is reset to the last one. I confess that I'm not really sure how. I just noticed that that's what it was doing and counted my blessings. I'm sure that my not understanding that is actually at the root of my current problem....
Hi all, I have managed to get the code working in that it passes the examples given in the doctring. I was so excited that I deleted the print statements that were helping me to debug from find_best_shifts_rec. However I had utter failure in decrypting the fable. I was able to get what I think are the first two words but nothing after that! Here is my code: http://pastebin.com/siNsuDze There are a ton of print statements that I put back in when I read here ( http://openstudy.com/updates/505696e0e4b02986d371002b) that I had to manually go through each letter until I found a space. Please let me know if I should clean up the code more. I apologize for the relative mess. I spent the last 3 hours figuring it out, almost getting it, then not having it work again so I'm a little frustrated. Thanks everyone!
Hi luik, since I"m just starting to learn myself, I'm reluctant to give you any feedback since who knows, I could be completely wrong. :| But thanks for posting; it helps to see what other people have come up with.
Hi ricketybridge, here's my solution: http://pastebin.com/n7g0F7Us This works with the given example and it also solves the fable. It looks like the fable has some random spelling errors... not sure if that's my code's fault or the fable's. I decided to ditch my old code and just follow the pseudocode example. Thankfully the pseudocode is pretty well-written and it didn't take too much debugging to figure out. That was pretty brutal... I'm not looking forward to the next problem set.
Hey clint, that's great! Thanks so much for sharing your code. It's really interesting how different yours is from mine. I'm going to be looking it over very carefully to see what about it makes it work that is lacking in mine...
Oh, and I've gotten my code to work well enough to decode the fable (it just doesn't return the shifts right) and I noticed not spelling errors, but just incorrect words. For instance, I have "ox ward" instead of "forward," which the actual word must be. I assume that that's just a problem with this particular method of decoding rather than an error in my code...?
Miraculously (there is no other word to describe it), I have managed to perfect my code, and the fable is returned with no errors. Alleluia! I learned a lot. About life, about myself. Here is my crowning glory: http://pastebin.com/fTdTnhpB
Awesome, congrats on that. Your code looks super clean... I'm going to take a look later. I wanted to celebrate too once I figured out mine....by punching my computer in the face. Maybe I'll see you in PS5...
Congratulations! I'm going to take a look at your code after a few more attempts at making mine work.
Join our real-time social learning platform and learn together with your friends!