Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← 04x-04 Party Time Solution

dummy description

Get Embed Code
3 Languages

Showing Revision 1 created 10/24/2012 by Amara Bot.

  1. I'm going to call my procedure sublists.
  2. We saw before when I drew it out that we wanted 2 arguments:
  3. the big list of people that I'm going to invite to my party
  4. and the people that I've selected so far.
  5. As we make recursive calls to sublists,
  6. the big list of people I've yet to invite will shrink,
  7. and then selected so far--the people who have showed up to my party--
  8. may or may not grow. They may show up or not.
  9. So this is a recursive procedure, and every recursive procedure needs a base case
  10. or a stopping condition.
  11. If there's no one left to invite, then I'll just print out the people we've selected so far.
  12. Remember when I drew the tree at the bottom there were 8 answers?
  13. When I get down to the end, I want to print out each of those 8 answers.
  14. If the big list is not empty, then it has at least 1 element--
  15. the current element, I'll call it--and then here I've just put the rest of the list,
  16. which is everything after the current element.
  17. May be empty; may have more things.
  18. In this recursive procedure, we're going to call ourselves 2 times.
  19. There's 1 case where the current person responds to our dinner invitation
  20. and ends up being one of the people we select,
  21. and there's another case where they do not. And that's actually it.
  22. Here's a test program.
  23. My dinner guests are Lucretia Mott, Elizabeth Cady Stanton, and Susan B. Anthony,
  24. and I'm going to call sublists, and the big list of people is dinner guests,
  25. and the people I've chosen so far is nothing.
  26. Let's see if this works.
  27. And in fact, we got just the answer we wanted.
  28. There's 1 world where everyone shows up,
  29. 1 world where no one shows up, 3 worlds with just 1 person,
  30. and 3 worlds with 2 people each, for a total of 8.