anonymous
  • anonymous
Problem with a recursive approach to problem set 2 question 2 (ps3b).
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
I always end up with the function yielding nested tuples, plus I could not do it without passing an additional arg. to the function to keep the length of the sliced string. http://dpaste.com/531825/ Any ideas?
anonymous
  • anonymous
Sorry, this question is in regards to problem set 3, not 2
anonymous
  • anonymous
I don't understand recursive functions enough to explain them but I can give you mine if you want it and you can try to figure it out?

Looking for something else?

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

More answers

anonymous
  • anonymous
that'll be great, thanks
anonymous
  • anonymous
http://dpaste.com/hold/531832/
anonymous
  • anonymous
to solve the nested tuple problem, instead of returning loc, subStringMatchRecursive(target,key,(loc+1)) you return things like loc + subStringMatchRecursive(target,key,(loc+1)) when you use a comma, even without parens it assumes your trying to make a tuple, or at least it does sometimes, its sketchy at best. when you use the "+", tried to create one whole thing. sometimes the tuple doesn't like to add with a non tuple, when that happens i find that you can help it along by putting the non tuple variable (say x) tuple + (x,) hopefully that made sense and i understood what was going wrong
anonymous
  • anonymous
Like Nessman said, you can fix your code by returning: (loc,) + subStringMatchRecursive(target,key,(loc+1)) You'll also have to seed an empty tuple instead of None, which is what you're implicitly seeding (by not having a return outside the while loop). You can do that by adding "return tuple()" outside your while loop. I've attached my ps3b.py for reference. I solved it three different ways, but my "subStringMatchExact2" is closest to your code.
1 Attachment

Looking for something else?

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