SJSU/Udacity CS046

Lesson 4 - Fundamental Data Types

  1. Introduction
  2. Introducing Ingrid
  3. Working with Numbers
  4. Quiz: Overflow
  5. Quiz: Precision
  6. Doubles Are Fuzzy
  7. Quiz: Number Types
  8. Quiz: Arithmetic Operations
  9. Quiz: Integer Arithmetic
  10. Quiz: Arithmetic Operations 2
  11. Ingrid Talks About Order of Operations
  12. Quiz: Color Reduction
  13. Quiz: Color Reduction 2
  14. Quiz: Day of the Week
  15. Quiz: Checkerboard
  16. Quiz: Casts
  17. How to Cast
  18. Quiz: Casts 2
  19. Ingrid Talks about Learning Casting
  20. Quiz: Grayscale
  21. Quiz: Math Functions
  22. Quiz: Sunset Effect
  23. Quiz: Magic Number
  24. Reading Input
  25. Quiz: Your Own Sunset Effect
  26. Formatted Output
  27. Quiz: Practice Formatted Output
  28. Quiz: Formatted Output Practice Part 2
  29. First Do It by Hand
  30. First Do It by Hand Part 2
  31. Quiz: Your Turn to Do It by Hand
  32. Quiz: Strings
  33. Working with Text
  34. Quiz: Working with the Book Text
  35. Quiz: Mad Hatter
  36. Quiz: Get the First Sentence
  37. Quiz: Get the Second Sentence
  38. Quiz: Occurrence of Alice
  39. Quiz: Occurrence of Any Word
  40. Quiz: Putting It All Together
  41. Quiz: Polish Our Code
  42. Calculating Circular Fields
  43. Formula for Calculating Circular Fields
  44. Quiz: How Many Rows of Fields
  45. Quiz: How Many Columns Can We Fit?
  46. Quiz: Number of Odd vs. Even Rows
  47. Quiz: How Many Fields Can We Fit?
  48. Quiz: Let's Program It Up
  49. How Programming Impacted Ingrid's Life
  50. Advice from Ingrid

Quiz: Color Reduction 2

1. Oops. I falsely say multiply by 5 when I should say multiply by 51.

2. Someone asked:

"We are dividing up our colors into certain (approximate) ranges: 0 to 43, 43 to 85, 85 to 128, 128 to 171, 171 to 213, and 213 to 255. In the reduction step however, we would round a value of 42 DOWN to 0 and a value of 214 UP to 255. Why not use the middle values of each range?"

That's a good question.

If you divide the range [0...255] into six equal intervals, and then map each to the midpoint, you lose black and white--the darkest you get is 21 and the whitest is 234.

If you want to round to the midpoint and preserve black and white, you want the first and last interval to have half the size of the others:

0 ----][-------][--------][--------][--------][---- 255

Then the formula would be

red = (red + 25) / 256 * 51;
...

Try it out and see if you like the result better.

Problem on this page?

Your name:

Your email address:

Problem description:

To protect against spam robots, please answer this simple math problem:
× =