01. What is programming? — Homework solutions

Part 1 homework has no .lua files. The walkthroughs below show example answers; yours will differ. What matters is spotting the same kinds of things.

Problem 1 — Spot the vague step

Problem. Find three vague steps in the tea recipe.

How to think about it. At each step, ask what would the computer not know? It can't guess amounts, durations, or preferences.

Sample answer.

  • Step 1: "Boil some water." Some is vague. How much? A cup? A litre?
  • Step 4: "Make it the right strength." Right is vague. How long does the tea bag stay in? Thirty seconds? Three minutes?
  • Step 5: "Add milk if you want." If you want is vague. The computer has no wants. It needs a yes/no question, like is milk on the request list?

Any three are fine. Steps 2 ("Get a tea bag") and 3 ("Put it in a mug") are tighter, but you could call them vague too — which tea bag, which mug — and you'd be right.

Problem 2 — Be the computer

Problem. Turn "Tidy your room" into 5-10 specific steps.

How to think about it. You're turning one fuzzy goal into many small clear ones. After each step, ask could the computer do it without asking a question? If no, the step is still too big.

Sample answer.

1. Pick up every item of clothing from the floor.
2. Sort the clothes into two piles: dirty and clean.
3. Put every dirty item in the laundry basket.
4. Fold every clean item and put it in the wardrobe.
5. Pick up every book from the floor.
6. Put each book on the bookshelf.
7. Throw away every piece of paper that is not a school book.
8. Wipe the desk with a cloth.
9. Run the vacuum over the floor once.
10. Open the curtains.

Each step starts with a verb (pick up, sort, put, fold, wipe, run, open) — a good habit. Vague nouns like organisation and tidiness aren't steps at all.

Problem 3 — Where would it break?

Problem. Does "pour half the bowl" still work if the recipe is doubled?

How to think about it. Half of the bowl is not a fixed amount. It depends on how full the bowl is. Twice as full means half is twice as much.

Sample answer.

The step still pours half the bowl, but that half is now twice the batter. The pan over-fills, and the pancakes spill over or come out too big.

A step that ignores fullness would say pour 200 ml of batter into the pan. Doubling the recipe then just means more pancakes from one bowl — the per-pancake amount stays right.

Same idea as a variable. Half the bowl depends on a value that can change; 200 ml does not. The first is more flexible, the second more predictable.

Challenge — The sandwich sheet

Problem. Write six steps for a sandwich that survive an adult trying to take every shortcut.

How to think about it. Every word that could be read two ways is a bug. Bread could be any bread, spread any thickness, sandwich any shape. Be ridiculously specific, then test it.

Sample answer.

1. Take two slices of white bread from the loaf on the kitchen counter.
2. Place both slices flat, side by side, on a clean plate.
3. Using a butter knife, spread one tablespoon of peanut butter
   across the entire top face of the LEFT slice.
4. Using a different butter knife, spread one tablespoon of
   strawberry jam across the entire top face of the RIGHT slice.
5. Pick up the right slice and place it, jam-side DOWN, directly
   on top of the left slice, so the two coated faces meet.
6. Place the finished sandwich on a clean napkin and hand it to me.

Hand this to a person and they'll still break it ("you didn't say which counter"). Smile and add the missing step. Code is like that: the first version is almost never strict enough.

Done?

The next chapter introduces flowcharts, a picture-based way to plan your steps before writing them down.