• The Amara On Demand team is looking for native speakers of German, Japanese, Korean, Italian, Hindi and Dutch to help with special paid projects
Apply here Hide

## ← Spreading Udaciousness Solution - Intro to Computer Science

• 3 Followers
• 25 Lines

### Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=q_atgGWy57Y" data-team="udacity"></div> ``` 3 Languages

Showing Revision 6 created 05/25/2016 by Udacity Robot.

1. So in this problem, we start out with n
number of people with big heads and happy smiles.
2. And after every hexamester, each one of
our happy udacians goes out and asks
3. spread number of their friends
to also take the course.
4. This process continues as long as the
number of udacians is less than the target.
5. With a little bit of math, you can solve
this pretty straightforward,
6. and you might have done it in
middle school or high school,
7. but we're going to use recursion
to solve this problem very easily.
8. Remember what we're looking for is the
number of hexamesters this process goes through
9. until we reach the target.
10. I saw on the forms a couple of people
were trying to use global variables
11. that counted recursive calls,
12. but really that kind of defeats the purpose in
the power that we can use in the recursion.
13. I'm going to show you how to do that right now.
14. So our base case says that if we've met our
target, then we don't need any time to spread
15. in order to reach the target because
16. Now here I have a + 1 because we're
going to say that we're doing 1 iteration
17. of the udacian spreading process.
18. Now for the recursive call.
19. The first thing we need is n.
20. Well, n is going to be the same thing as last
time + how many new people we've gotten,
21. which is spread x n.
22. A more succinct way of writing this would
be simply (n x (1 + spread).
23. The spreading rate doesn't change,
so we're going to leave that alone.
24. Our target doesn't change.
25. And that's it. We're done.