Chapter 3 Walkthrough

Cubes

  • List: all perfect cubes divisible by 16 and less than N.
  • Write signature.
cubes 100 == [64]
cubes 600 == [64, 512]

Partial Average

  • Average first N items of a list.
  • Write signature.
partAvg 3 [10,15,50,10000] == 25

Say GPA

  • Make a string “My GPA is 3.10”.
  • Number is parameter.
  • Write signature.
sayGPA 3.10 == "My GPA is 3.10"

Count Up I

  • Given start and end numbers, print a string.
  • Usage: countUp 3 7
  • Result: “I can count from 3 to 7: [3, 4, 5, 6, 7]”
countUp 3 7 == "I can count from 3 to 7: [3, 4, 5, 6, 7]"

Count Up II

  • Given strings containing start and end numbers, as if typed.
  • Same as Count Up I.
countUpII "3" "7" == "I can count from 3 to 7: [3, 4, 5, 6, 7]"

Need read?

Use type signatures and helper functions.


Sample Standard Deviation

Input a list of numbers, say there are n of them.

  1. Find the average (called “xbar”).
  2. Find the sum of (x-xbar)^2 for each x in the list.
  3. Divide by n-1.
  4. Take the square root.