← What the Snack Machine Knows · Lesson 1 of 3
The machine remembers one number
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 one number a snack machine remembers
An exact-change machine sells a snack for 90¢ and takes only 20¢ coins. How many of its states can still reach the price?