Guide · Coffee and code

An algorithm for making a cup of coffee.

An algorithm is a list of exact steps that ends with a result. Making coffee is the classic example from computer class. Here it is precise enough to brew a good cup: with amounts, times, two decisions and a loop.

Input
15 g · 250 gCoffee and water, a ratio of about 1:16.7
Water
93 °C30 to 60 seconds after it boils
Run time
2:45–3:30From the first pour until it has run through
Output
1 cupAnd what to change next time

The three building blocks

  • SequenceThe steps run in a fixed order. You grind before you pour, and you rinse the filter before the coffee goes in.
  • SelectionIF the water ran through before 2:45, THEN grind finer next time. IF it took longer than 3:30, grind coarser.
  • IterationWAIT UNTIL the dripper is empty: you check again and again until the condition is true.

The algorithm in 8 steps

You need a pour-over dripper such as the Hario V60, a paper filter, a grinder, a kettle, a scale and a timer.

  1. 1

    Heat the water to 93 °C

    Heat more water than you need, about 400 g: some of it goes into rinsing the filter. No thermometer? Start the bloom 30 to 60 seconds after it boils.

  2. 2

    Weigh 15 g of coffee and grind it

    While the water heats, grind medium-fine, about like table salt. Grind right before brewing: ground coffee loses its aroma within minutes.

  3. 3

    Rinse the filter

    Put a paper filter in the dripper, set it on the cup and pour hot water through. That removes the taste of paper and warms everything up. Pour the rinse water away.

  4. 4

    Coffee in, scale to zero

    Put the ground coffee in the filter, shake it level and set cup and dripper on the scale. Set the scale to zero.

  5. 5

    Bloom: 45 g, then wait

    Start the timer and pour 45 g of water, just enough to wet all the coffee. Swirl once. The coffee bubbles: that is CO₂ escaping. Wait until the timer shows 0:35.

  6. 6

    Pour to 150 g, then to 250 g

    Pour in slow spirals until the scale shows 150 g. At 1:15, pour on to 250 g. That is the whole water: 15 g of coffee to 250 g of water, a ratio of about 1:16.7.

  7. 7

    Swirl, wait until it has run through

    At 2:00, swirl the dripper once so the coffee bed lies flat. Then wait until no more water drips through.

  8. 8

    Check the time, then taste

    Read the timer. Done before 2:45? Grind finer next time. Took longer than 3:30? Grind coarser. Anything in between: drink it. In time but sour? Grind a little finer. Bitter and dry? A little coarser.

The same recipe with a timer that counts along and a calculator for more cups: Hario V60 guide.

As pseudocode

The same steps, written the way you would write them in computer class. Every value is a number you can measure, so every line can be carried out exactly.

INPUT  coffee ← 15 g, water ← 250 g, temp ← 93 °C

boil(water)
grind(coffee, "medium-fine")
rinse(filter); add(coffee); scale ← 0
WAIT 30–60 s after boil   // about 93 °C

start(timer)
pour(45 g); swirl()
WAIT UNTIL timer = 0:35
pour() UNTIL scale = 150 g
WAIT UNTIL timer = 1:15
pour() UNTIL scale = 250 g
WAIT UNTIL timer = 2:00
swirl()
WAIT UNTIL dripper is empty

IF timer < 2:45 THEN next.grind ← finer
ELSE IF timer > 3:30 THEN next.grind ← coarser
END IF

OUTPUT cup   // taste it

As a flowchart

An oval marks start and end, a rectangle a step, a diamond a decision. The loop is the arrow that leads from "Wait" back up to the question.

Flowchart: making a cup of coffee no yes yes no yes no StartHeat water to 93 °C,grind 15 g of coffeeRinse the filter, coffee in,scale to zeroPour 45 g,wait until 0:35Pour to 150 g,at 1:15 on to 250 gAt 2:00: swirl once All runthrough?Wait Done before2:45?Next time:grind finer Took longerthan 3:30?Next time:grind coarser Drink

The short version for homework

Most worksheets want something simpler. This version still has all three building blocks.

  1. Fill the kettle with water and switch it on.
  2. Put a paper filter in the dripper and ground coffee in the filter.
  3. Wait until the water boils, then let it stand for 30 seconds.
  4. Pour the water over the coffee and wait until it has run through.
  5. If you take milk, add milk.
  6. If you take sugar, add sugar and stir until it has dissolved.
  7. Serve the coffee.

Sequence: steps 1 to 7 in order. Selection: steps 5 and 6. Iteration: waiting until the water boils, and stirring until the sugar has dissolved. What the short version leaves out is how much coffee, how hot and how long. That is why the long version makes the better cup.

FAQ

What is an algorithm for making coffee?

A fixed series of steps that turns water and ground coffee into a cup, and that always comes to an end. The version on this page has 8 steps, two decisions about the brew time and a loop that waits until the water has run through.

Which building blocks does the coffee algorithm use?

All three: sequence (the steps in a fixed order), selection (IF it ran through too fast, THEN grind finer) and iteration (WAIT UNTIL the dripper is empty, or stir until the sugar has dissolved).

How do I draw it as a flowchart?

An oval for start and end, a rectangle for each step, a diamond for each decision, and arrows between them. A decision gets two arrows, labelled yes and no. These symbols are standardized in ISO 5807. The flowchart above uses them.

Why does the algorithm need exact numbers?

"Add some coffee" cannot be carried out exactly. With 15 g, 250 g and 93 °C you can repeat a cup, and when it does not taste right, you know which value to change.

How much coffee for more cups?

Keep the ratio and scale both values: 30 g of coffee to 500 g of water makes two cups. Expect it to run 30 to 60 seconds longer. The calculator on the brew guides page works it out for any number of cups.

The amounts, temperature and times are those of our Hario V60 recipe. Flowchart symbols follow ISO 5807.