English subtitles

← 02-34 Timed Calls Solution

Get Embed Code
1 Language

Showing Revision 1 created 04/23/2012 by Amara Bot.

  1. Here is my answer.
  2. If it's integer, we do what we did before.
  3. Otherwise, we go into a loop until the sum of the times is greater than or equal
  4. to the floating point number that passed in.
  5. Now I think we've got a pretty good handle on timing our functions.
  6. Another interesting question would be how many assignments
  7. did we take along the way, not just how long did they take?
  8. Now, if our program had been structured using for statements
  9. rather than using the big generator expression,
  10. we could do it something like this.
  11. We could say we're going to count the number of assignments.
  12. We're going to start the count at 0, and then every time we go through an ordering
  13. we're going to increment the count by 1.
  14. You might say we want to increment the count by 5,
  15. because we've assigned each of the 5 houses one of the colors,
  16. but I'm counting that as 1. You can choose which one you want to go on.
  17. Then we just have a structure like that, and we can keep track of the counts.
  18. That will work fine, and it's not too bad, but it bothers me a little bit
  19. that we had to do such violence to this program.
  20. We had this program, and we had to go in in so many places,
  21. interrupt it, and put in so many statements.
  22. I wanted to see can we separate that out a little bit?