Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

harsimran_hs4

hi guys i am facing problem in ps4 (6.00, 2011) in the function find_best_shifts(wordlist, text)[part 4 of ps4], it is returning none type instead of some list of tuples can you tell me the mistake... [this part has been solved in discussion] the code is here: http://pastebin.com/VvGpMb5S NOW THE PROBLEM is to correct the function find_best_shifts()

  • one year ago
  • one year ago

  • This Question is Closed
  1. TuringTest
    Best Response
    You've already chosen the best response.
    Medals 0

    why do you have maxwords=0 ?

    • one year ago
  2. TuringTest
    Best Response
    You've already chosen the best response.
    Medals 0

    oh I see, nevermind

    • one year ago
  3. TuringTest
    Best Response
    You've already chosen the best response.
    Medals 0

    try inserting some print statements, like print every new best shift to see if you are entering all the loops

    • one year ago
  4. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    dont know if that helps(or if im wrong) but on line 345 you call : find_best_shifts_rec(wordlist, text, 0) . i believe you need a return for it since its in a def function. so it should be: return find_best_shifts_rec(wordlist, text, 0)

    • one year ago
  5. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    @MicroBot thanks that worked i.e it returned the value but still it`s not giving the correct output as given in the problem set. this portion >>> s = apply_shifts("Do Androids Dream of Electric Sheep?", [(0,6), (3, 18), (12, 16)]) >>> s 'JufYkaolfapxQdrnzmasmRyrpfdvpmEurrb?' >>> shifts = find_best_shifts(wordlist, s) >>> print apply_shifts(s, shifts) Do Androids Dream of Electric Sheep? but it giving something weird, please can you tell the mistake that still exists....

    • one year ago
  6. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    @MicroBot and @TuringTest Guys help please.....especially you have been quite good at clearing my problems looking forward for a reply...

    • one year ago
  7. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    oh sry was late when i read it and i said ill respond tomorrow! then i forgot xD let me see if i can figure smthing out!

    • one year ago
  8. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    @harsimran_hs4 can you link me to the problelm set ? as im not doint this course ...just did a similar one on edx courses.

    • one year ago
  9. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    the test which i mentioned above i did return the list of tuples with six elements of which 1st three were correct and the other three were extra ....maybe this will help you in figuring out the problem

    • one year ago
  10. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    by loading your code i get this: Loading word list from file... 55909 words loaded. recShifts : [(30, 0)] recShifts : [(30, 0)] recShifts : [(21, 0), (30, 0)] recShifts : [(21, 0), (30, 0)] recShifts : [(18, 0), (21, 0), (30, 0)] recShifts : [(18, 0), (21, 0), (30, 0)] recShifts : [(12, 16), (18, 0), (21, 0), (30, 0)] recShifts : [(12, 16), (18, 0), (21, 0), (30, 0)] recShifts : [(3, 18), (12, 16), (18, 0), (21, 0), (30, 0)] recShifts : [(3, 18), (12, 16), (18, 0), (21, 0), (30, 0)] is it the same you get?

    • one year ago
  11. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    yes !! if you comment out the print statement then it returns [(3, 18), (12, 16), (18, 0), (21, 0), (30, 0)] this is the test i was running : >>> s = apply_shifts("Do Androids Dream of Electric Sheep?", [(0,6), (3, 18), (12, 16)]) >>> s 'JufYkaolfapxQdrnzmasmRyrpfdvpmEurrb?' >>> shifts = find_best_shifts(wordlist, s) #here i should get the same shifts i used to code it >>> print apply_shifts(s, shifts) Do Androids Dream of Electric Sheep? And use this code http://pastebin.com/NDxdNMJB it will return [(0, 6), (3, 18), (12, 16), (18, 0), (21, 0), (30, 0)] a little better than before as it`s returning (0,6) also

    • one year ago
  12. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    im trying it right now(forgive me if im slow but its new to me aswell since for my course i didnt have the multiple encryption part)

    • one year ago
  13. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    ok Thanks for taking pain to help me out ... you will surely enjoy this part of multiple encryption it's quite interesting and maybe a little time consuming also...

    • one year ago
  14. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    ye i actually find it very interesting:)plus debugging and understanding other ppl code is a great way to learn.

    • one year ago
  15. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    +1 for {plus debugging and understanding other ppl code is a great way to learn.} Yes indeed thats great way to learn do message me whenever you get to a solution !!!

    • one year ago
  16. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    i sure will!

    • one year ago
  17. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    ok this is what i see: see this code (its your code with more print statements and more test cases): http://pastebin.com/LZ3attfE i believe you have written your function around the test case you were doing ...means your code searches the best shifts for starters that are after ' '(space chars) only....you can see that if you put different starters that are not space chars. Thats why you get the 3 starters that you dont need....cause it searches every ' ' char in the string. sry i explain bad ,,,but if you see the code and the output i believe youll understand what i mean.

    • one year ago
  18. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    let me know how it is going:)

    • one year ago
  19. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    thanks but can you explain " you can see that if you put different starters that are not space chars." as far as i get it is giving the last step i.e the first start point as three outputs where as we don`t need all.....is it this bug you are talking about? and also we need to apply the shifts we get from find_best_shifts(wordlist, s) in the negetive order...is it so?

    • one year ago
  20. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    and how are the test1 and test2 different from each other ?

    • one year ago
  21. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    goodmorning:) let me see again:)

    • one year ago
  22. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    ok 1st how the test 1 is different from test 2: on test1 you apply shifts starting from the char after every space in the string. and your findbestshifts is based on that!(that the code is applied after every space in the string. on test 2 you apply shifts on random chars in the string... does it sound better now?

    • one year ago
  23. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    >>> Loading word list from file... 55909 words loaded. shifts : [(0,6), (3, 18), (12, 16)] s : JufYkaolfapxQdrnzmasmRyrpfdvpmEurrb? space is at index: 2 space is at index: 11 space is at index: 17 space is at index: 20 space is at index: 29 recShifts1 : [(30, 0)] recShifts2 : [(30, 0)] recShifts1 : [(21, 0), (30, 0)] recShifts2 : [(21, 0), (30, 0)] recShifts1 : [(18, 0), (21, 0), (30, 0)] recShifts2 : [(18, 0), (21, 0), (30, 0)] recShifts1 : [(12, 16), (18, 0), (21, 0), (30, 0)] recShifts2 : [(12, 16), (18, 0), (21, 0), (30, 0)] recShifts1 : [(3, 18), (12, 16), (18, 0), (21, 0), (30, 0)] recShifts2 : [(3, 18), (12, 16), (18, 0), (21, 0), (30, 0)] bestSHIFTS : [(0, 6), (3, 18), (12, 16), (18, 0), (21, 0), (30, 0)] ..................... shifts : [(2,6), (5, 18), (10, 16)] s2 : DofGtaolfaemQdrnzmasmRyrpfdvpmEurrb? SHIFTS : None >>> this is what i get by applying those 2 tests

    • one year ago
  24. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    ok i got it.....now i think i will have review the code again , a little more deep insight into it would help (get back soon with the test3 ) do keep writing of the progress you make in this problem

    • one year ago
  25. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    i am doing the 3rd test fopr you now so you can see:) ill ask a friend on what he thinks about it...

    • one year ago
  26. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    ok thanks you also continue with test3 and yes reference from another person would help....:)

    • one year ago
  27. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    @harsimran_hs4 do you too see that you implemented the code just for the test 1 to come true? if you see smthing else say so...

    • one year ago
  28. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    http://pastebin.com/dw32HKNY with test 3 that is the same as test 1 just with other shift

    • one year ago
  29. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    or even better you can change last test's shifts to this [(0,8), (3, 5), (12, 5),(21,2)]

    • one year ago
  30. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    yes i wrote it to come true only for those which start at spaces........ so that means it will not work for test 2 and test 3 in test 3 you have applied shifts which start at the spaces, is it so ? how did you deduce [(0,8), (3, 5), (12, 5),(21,2)] from [(0, 8), (3, 5), (12, 5), (18, 0), (21, 0), (30, 0)]

    • one year ago
  31. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    nono just chenge the test ..thats what i mean....21 is a char just after a space since in that specific text the spaces are on: space is at index: 2 space is at index: 11 space is at index: 17 space is at index: 20 space is at index: 29 as you can see in your output so i just ask the program to apply shift there aswell

    • one year ago
  32. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    ok..

    • one year ago
  33. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    Hint: You will find this function much easier to implement if you use recursion. (as said in the comments) i think you should use recursive function to find_best_shift function (not find_best_shiftS)

    • one year ago
  34. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    isn't it what i implemented in find_best_shifts_rec() ?

    • one year ago
  35. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    recShifts = find_best_shifts_rec(wordlist, new_string, i+1) this you mean? no i mean the find_best_shift(wordlist,text) line 249 if that can help....just dont know how!:P

    • one year ago
  36. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    wish smone could help us out here xD

    • one year ago
  37. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    id recursively run that function (find_best_shift for text[start:] where start ==word in wordlist(the next char just after it)

    • one year ago
  38. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    maybe i`ll have to approach the question with a somewhat better approach using all the suggestions in the discussion. hey you are taking Edx course ...if yes then do you have any provision of asking mentors or teachers....maybe they could help and advice us better

    • one year ago
  39. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    there is only a discussion forum but usually teachers do not answer but student do ..so its kinda the same.

    • one year ago
  40. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    and most of them are here too

    • one year ago
  41. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    btw @thepenguin since you are doing the same problem join us here:)

    • one year ago
  42. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    rethink it a bit ...i have to go study for edx:P xD when you have some new ideas post it here so we can discuss:)

    • one year ago
  43. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    yes sure!!

    • one year ago
  44. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    @MicroBot the problem was what we got when we did >>> s = apply_shifts("Do Androids Dream of Electric Sheep?", [(0,6), (3, 18), (12, 16)]) >>> s 'JufYkaolfapxQdrnzmasmRyrpfdvpmEurrb?' >>> shifts = find_best_shifts(wordlist, s) NOTE:*look below >>> print apply_shifts(s, shifts) Do Androids Dream of Electric Sheep? NOTE: before apply shifts we need to reverse them and take the negetive of the shift (as we are doing the reverse process of encrypting i.e deciphering) we got [(0, 8), (3, 5), (12, 5), (18, 0), (21, 0), (30, 0)] hence we must generate a list say correct = [(30, 0), (21, 0), (18, 0), (12, -5), (3, -5), (0, -8)] and then print apply_shifts(s, correct) and this works pretty well i hope you get what i am saying as i don`t explain that well

    • one year ago
  45. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    i deciphered the text file fable this is what i got : An Ingenious Man who had built a flying machine invited a great concourse of people to see it go up. at the appointed moment, everything being ready, he boarded the car and turned a a he power. the machine immediately broke through the massive substructure upon which it was builded, and sank out of sight into the earth, the aeronaut springing out barely in time to save himself. "well," said he, "i have done enough to demonstrate the correctness of my details. the defects," he added, with a add hat the ruined brick work, "are merely basic and fundamental." upon this assurance the people came ox ward with subscriptions to build a second machine

    • one year ago
  46. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    this is the corrected code: http://pastebin.com/axHn8mLH i have made changes in find_best_shifts() in the code in test1 after line 392 just add print apply_shifts(s, shifts) output is : Loading word list from file... 55909 words loaded. shifts : [(0,6), (3, 18), (12, 16)] s : JufYkaolfapxQdrnzmasmRyrpfdvpmEurrb? bestSHIFTS : [(30, 0), (21, 0), (18, 0), (12, -16), (3, -18), (0, -6)] Do Androids Dream of Electric Sheep? .....................

    • one year ago
  47. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    uhm could you please link me to the fable.txt so i can download it somewhere?

    • one year ago
  48. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    i have already linked you to ps4 it is one of the files in zip folder there for download

    • one year ago
  49. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    ok sec

    • one year ago
  50. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    >>> ================================ RESTART ================================ >>> Loading word list from file... 55909 words loaded. >>> print decrypt_fable() i get stuck there...it just stays like this wont do anything...not sure if its veeeeeeeeeeeeeery slow or what.

    • one year ago
  51. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    yes it`s slow just run and it would take something around 5-10 min i suppose to run {for the length of trials : just try and print the find_best_shifts() and you will find that the length of the list is quite large....so perhaps the fable has been coded nicely :)}

    • one year ago
  52. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    ok ill let it run then

    • one year ago
  53. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    it took me around 10 min (i ran it just now).....what about you?

    • one year ago
  54. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    yes it finished and worked (GJ) but i still have to see smthing i dont understand

    • one year ago
  55. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    print '.....................' s = random_scrambled(wordlist, 3) print s shifts = find_best_shifts(wordlist, s) print 'bestSHIFTS : ',shifts print apply_shifts(s, shifts) print '......................' doing this test seems to work perfectly!congratz!

    • one year ago
  56. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    if im not reading wrong ,random_scrambled its applying shifts that are after each space char aswell ,so yes then you were totaly right to write findbestshifts for space chars! so it should only work for that ...i didnt know thats why i was testing it for any index in the string.

    • one year ago
  57. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    yes that was only for applying shifts from start of a word..... it was great experience collaborating with you Thanks!!

    • one year ago
  58. MicroBot
    Best Response
    You've already chosen the best response.
    Medals 1

    Well same goes for me!It was great doing this! Ask me anytime to join you :)

    • one year ago
  59. harsimran_hs4
    Best Response
    You've already chosen the best response.
    Medals 1

    yes sure!!!

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.