Quantcast

A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

harsimran_hs4

  • 2 years ago

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()

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

    why do you have maxwords=0 ?

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

    oh I see, nevermind

  3. TuringTest
    • 2 years ago
    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

  4. MicroBot
    • 2 years ago
    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)

  5. harsimran_hs4
    • 2 years ago
    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....

  6. harsimran_hs4
    • 2 years ago
    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...

  7. MicroBot
    • 2 years ago
    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!

  8. MicroBot
    • 2 years ago
    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.

  9. harsimran_hs4
    • 2 years ago
    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

  10. MicroBot
    • 2 years ago
    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?

  11. harsimran_hs4
    • 2 years ago
    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

  12. MicroBot
    • 2 years ago
    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)

  13. harsimran_hs4
    • 2 years ago
    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...

  14. MicroBot
    • 2 years ago
    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.

  15. harsimran_hs4
    • 2 years ago
    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 !!!

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

    i sure will!

  17. MicroBot
    • 2 years ago
    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.

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

    let me know how it is going:)

  19. harsimran_hs4
    • 2 years ago
    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?

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

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

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

    goodmorning:) let me see again:)

  22. MicroBot
    • 2 years ago
    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?

  23. MicroBot
    • 2 years ago
    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

  24. harsimran_hs4
    • 2 years ago
    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

  25. MicroBot
    • 2 years ago
    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...

  26. harsimran_hs4
    • 2 years ago
    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....:)

  27. MicroBot
    • 2 years ago
    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...

  28. MicroBot
    • 2 years ago
    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

  29. MicroBot
    • 2 years ago
    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)]

  30. harsimran_hs4
    • 2 years ago
    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)]

  31. MicroBot
    • 2 years ago
    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

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

    ok..

  33. MicroBot
    • 2 years ago
    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)

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

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

  35. MicroBot
    • 2 years ago
    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

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

    wish smone could help us out here xD

  37. MicroBot
    • 2 years ago
    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)

  38. harsimran_hs4
    • 2 years ago
    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

  39. MicroBot
    • 2 years ago
    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.

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

    and most of them are here too

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

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

  42. MicroBot
    • 2 years ago
    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:)

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

    yes sure!!

  44. harsimran_hs4
    • 2 years ago
    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

  45. harsimran_hs4
    • 2 years ago
    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

  46. harsimran_hs4
    • 2 years ago
    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? .....................

  47. MicroBot
    • 2 years ago
    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?

  48. harsimran_hs4
    • 2 years ago
    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

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

    ok sec

  50. MicroBot
    • 2 years ago
    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.

  51. harsimran_hs4
    • 2 years ago
    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 :)}

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

    ok ill let it run then

  53. harsimran_hs4
    • 2 years ago
    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?

  54. MicroBot
    • 2 years ago
    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

  55. MicroBot
    • 2 years ago
    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!

  56. MicroBot
    • 2 years ago
    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.

  57. harsimran_hs4
    • 2 years ago
    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!!

  58. MicroBot
    • 2 years ago
    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 :)

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

    yes sure!!!

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy

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.