Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
harsimran_hs4
Group Title
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()
 2 years ago
 2 years ago
harsimran_hs4 Group Title
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()
 2 years ago
 2 years ago

This Question is Closed

TuringTest Group TitleBest ResponseYou've already chosen the best response.0
why do you have maxwords=0 ?
 2 years ago

TuringTest Group TitleBest ResponseYou've already chosen the best response.0
oh I see, nevermind
 2 years ago

TuringTest Group TitleBest ResponseYou've already chosen the best response.0
try inserting some print statements, like print every new best shift to see if you are entering all the loops
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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)
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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....
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
@MicroBot and @TuringTest Guys help please.....especially you have been quite good at clearing my problems looking forward for a reply...
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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!
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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.
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
http://ocw.mit.edu/courses/electricalengineeringandcomputerscience/600scintroductiontocomputerscienceandprogrammingspring2011/unit2/lecture10hashingandclasses/ problem set 4 (The Caesar Cipher)
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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?
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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)
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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...
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
ye i actually find it very interesting:)plus debugging and understanding other ppl code is a great way to learn.
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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 !!!
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
i sure will!
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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.
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
let me know how it is going:)
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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?
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
and how are the test1 and test2 different from each other ?
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
goodmorning:) let me see again:)
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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?
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
i am doing the 3rd test fopr you now so you can see:) ill ask a friend on what he thinks about it...
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
ok thanks you also continue with test3 and yes reference from another person would help....:)
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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...
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
http://pastebin.com/dw32HKNY with test 3 that is the same as test 1 just with other shift
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
or even better you can change last test's shifts to this [(0,8), (3, 5), (12, 5),(21,2)]
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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)]
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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)
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
isn't it what i implemented in find_best_shifts_rec() ?
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
wish smone could help us out here xD
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
id recursively run that function (find_best_shift for text[start:] where start ==word in wordlist(the next char just after it)
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
there is only a discussion forum but usually teachers do not answer but student do ..so its kinda the same.
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
and most of them are here too
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
btw @thepenguin since you are doing the same problem join us here:)
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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:)
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
yes sure!!
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.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? .....................
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
uhm could you please link me to the fable.txt so i can download it somewhere?
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
i have already linked you to ps4 it is one of the files in zip folder there for download
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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.
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
yes it`s slow just run and it would take something around 510 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 :)}
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
ok ill let it run then
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
it took me around 10 min (i ran it just now).....what about you?
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
yes it finished and worked (GJ) but i still have to see smthing i dont understand
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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!
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.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.
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
yes that was only for applying shifts from start of a word..... it was great experience collaborating with you Thanks!!
 2 years ago

MicroBot Group TitleBest ResponseYou've already chosen the best response.1
Well same goes for me!It was great doing this! Ask me anytime to join you :)
 2 years ago

harsimran_hs4 Group TitleBest ResponseYou've already chosen the best response.1
yes sure!!!
 2 years ago
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
 Engagement 19 Mad Hatter
 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.