Skip to content
the grown-up commonsPlay togetherBack to room

← What the Snack Machine Knows · Lesson 1 of 3

The machine remembers one number

About it

An exact-change snack machine keeps track of a single thing: how much money has gone in so far. That number is its state. A coin is an input that moves it to the next state, and a coin that would carry it past the price is refused. When the state equals the price, the snack drops.

Drawn out, that is a finite automaton, the first machine in most introductions to computer science. A machine selling a $1.25 snack on quarters has six states: 0, 25, 50, 75, 100 and 125 cents. Change the coins and some states become dead ends. On dimes alone no state can ever reach $1.25, because 125 is not a multiple of 10.

Children meet this on CodeRealm by putting coins into a pretend machine and finding which coins strand them. Adding a nickel fixes every dead end: 5 divides 125 and every gap on the way.

The figure

The one number a snack machine remembers

0¢+25¢25¢+25¢50¢+25¢75¢+25¢100¢+25¢125¢the snack drops, and the machine starts againthe pricea coin that would go past the price is refused
A machine selling a $1.25 snack on quarters, drawn as its six states: 0, 25, 50, 75, 100 and 125 cents. Each quarter moves it one state to the right. At 125 the snack drops and it goes back to 0; a coin that would carry it past the price is refused.
One question

An exact-change machine sells a snack for 90¢ and takes only 20¢ coins. How many of its states can still reach the price?

Say it back
A lesson is kept once you've answered the question and written at least 8 words. Nobody grades it; it stays on this device.