YouTube

Got a YouTube account?

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

English subtitles

← Blank Tiles Solution - Design of Computer Programs

Get Embed Code
1 Language

Showing Revision 4 created 05/24/2016 by Udacity Robot.

  1. Here is my solution to the blanks problem.
  2. What I've decided is I'm going to represent blank tiles by the lowercase letter
  3. as long as I can--keep it in there up to the moment when I place them on the board.
  4. Here is the list of points that we had before, the points dictionary originally
  5. had a value of 0 for the underscore character.
  6. I've taken that out, because I'm not going to use the underscore character.
  7. I'm going to immediately translate the underscores into a lowercase letter.
  8. I have to figure out what are my lowercase letters?
  9. I get them by lowercasing the letters I already had,
  10. and then I went through the lowercase letters and I said the point value
  11. of a lowercase letter of a blank used as that lowercase letter is zero,
  12. updating the points dictionary.
  13. Now, my plays are going to be words that include lowercase letters in them.
  14. The best play might be something like this
  15. where we have the score, the location, the direction, and the word includes a lowercase letter.
  16. Because I've taken that approach and because I've defined the value of a to be zero,
  17. it turns out I don't have to change calculate_score at all.
  18. I can leave that alone.
  19. The only things I need to change are find_prefixes and add_suffixes.
  20. Let's look at find_prefixes.
  21. A lot of it is the same, but there are two places where I make a change.
  22. First, here before I was checking to see if the input pre was a member of WORDS
  23. or a member of PREFIXES.
  24. Here I created the new variable capital PRE and ask is that in the WORDS,
  25. because the thing I'm going to be passed in could look something like that.
  26. It could have a lowercase a in it, and that's not going to be in my dictionary of words.
  27. So I have to uppercase it before I can test.
  28. Like before, I test to see if I'm in the words.
  29. Then if I have a good prefix, then I go through my letters in the hand.
  30. Here's the second change.
  31. If the letter is a blank, then I go through all the possible lowercase letters,
  32. and try to find a prefix by replacing the letter, taking out the blank from the hand,
  33. and adding on the letter C onto the prefix.
  34. Otherwise, I just do what I did before.
  35. If it's not a blank, I remove the letter L and add it onto the prefix.
  36. That's find_prefix--very simple change.
  37. Now for add_suffixes.
  38. Again, two very similar changes just like we saw before.
  39. When we're looking up in the dictionary we have to look up an uppercase version
  40. of the prefix rather than the original prefix.
  41. While we're going through the hand, first we have to say is the letter one of the possibilities,
  42. one of the allowable results for the anchor.
  43. If that's the case, then go ahead and just use it.
  44. Otherwise, if we have a blank anywhere in the hand,
  45. then it's possible to use that at this point.
  46. We consider all the possible letters that might occur in this point.
  47. Before we iterated over the letters in the alphabet,
  48. but here we're iterating over the possible acceptable letters
  49. that the blank could stand for, and for each of them take away the blank,
  50. add on the prefix, but make it be lowercase to indicate that this
  51. is going to be represented by a blank.
  52. Let me just reformat that, because it's going off the page.