Countdown

Alphie and Betsy are trying to build a block to generate a list of whole numbers from n down to 1.
Alphie: I used a script variable and kept shoving a new number at the beginning of the list using for.
countdown using a for-loop
Betsy: Let's try it!
They take it out for a spin.
Alphie: Oh. Not what I expected...
  1. Fix Alphie and Betsy's countdown script so that it does what it's supposed to do.
Now Is a Good Time to Save
Gamal joins the group and looks over Alphie's shoulder.
Gamal: Wow, it would never have occurred to me to write it that way! You want countdown (5) to report the list {5, 4, 3, 2, 1}. But countdown (4) is {4, 3, 2, 1}, so all you have to do is stick a 5 in front:
define countdown (n): if n=0 report empty list, otherwise report (n) in front of (countdown (n-1))
Talk with Your Partner
  1. Gamal's description of his algorithm didn't mention the if in his code. What would happen if he left that part out? Why?