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

Folks..I have a doubt about the 1st question in problem set 2...the DNA matching one.. let the target be gcATATATgc and the key be ATAT what is the code supposed to return? 1 or 2?...i mean if u look at it as ATAT and AT the answer should be 1 and if u look at it as ATAT and ATAT (the middle AT is taken in both terms) the answer should be 2 I have very little knowledge of biology..so i am a bit confused .. codes are ready for both possibilities though ;)

OpenStudy (anonymous):

2

OpenStudy (anonymous):

Here is my answer then..please check n rectify.. and comment if anything can be done in a simpler better way ;) http://dpaste.com/hold/564850/

OpenStudy (anonymous):

It looks okay, have you tested it against the test ones in the template? Next step is to write it recursively.

OpenStudy (anonymous):

well i dont quite get the idea of recursion..still trying figure out how to do it recursively...let me try.. And about testing the code...i just tested some examples of my one..they worked fine..

OpenStudy (anonymous):

Yeah, I found this really hard. But I guess the idea is to learn to program recursively in this problem.

OpenStudy (anonymous):

this is the recursive one.. was really pretty hard to understand...made it after thinking hard for a total hour ..watched the recursion part of the video thrice :( http://dpaste.com/hold/565321/

OpenStudy (anonymous):

a bit of mistake in that code...just removed the print line.. it tends to print the line multiple times :(

OpenStudy (anonymous):

sunu! thank you so much... I get it now... the recursive is indeed much more elegant. Question though: shouldn't line 9 of the code read return 1+ cSMR(target[found+1:],key) The reason being in recursive code don't you want to recall the same function?? yours reads cSM and recalls the iterative function you wrote at the beginning of the problem.

OpenStudy (anonymous):

OOPSY sorry...a R is missing there ;) take a look now http://dpaste.com/hold/565668/

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!