Peace For All

May 28, 2006

Every Pop Machine is also a Quarter Machine

Filed under: Life in general, technology — Devlin Bentley @ 4:48 pm

One of the disadvantages of living in an apartment is the constant need for quarters in order to do the laundry every week. Typically this means either going down to the bank to get a roll of quarters, or trying to find a kindly cashier at the grocery store who is willing to part with one of their precious quarter rolls.

Needless to say, this gets inconvenient, especially since I never really, you know, plan my day around getting a pack of quarters. When Saturday comes, I do laundry, end of story. Having to drop what I am doing to run out to the store or bank in order to pick up a pack of quarters is not very convenient.

There is also a pop machine right outside my apartment room. I don't drink pop (except for the 4 liters of diet coke that I got for free two days ago, but that is a separate story!) so I never had cause to even think about the machine. At least, not until I had an epiphany.

Who ever programmed that pop machine was trained as either a software or a hardware engineer. They are my brethren, no?

A ordinary person would expect that if they put in 65 cents of coins into the machine, that when they pressed "coin return" that they would be given back the same coins that they put in. That makes sense, they put in some money, now they want it back, so they get back the money that they put in.

But I thought about if for a bit, how would I go about and program the pop machine to give back money after the user had hit "coin return"? It is rather foolish to just return the money that was put in, since I also need to give change when the user pays to much (such as putting in a dollar for a 65 cent can of pop). Thus a path from the change box in the machine to the coin chute is needed. It is therefore redundant, and an unnecessary cost, to also build a path from the coin entrance to the coin return chute. It makes more sense to just call the giveChange(int val) function and pass in for val how much money the user has already inserted.

Now how would I compute the types of coins to give back to the user to add up to val? Naturally, I would use the change giving algorithm, known to every computer scientist, engineer, and anybody who has ever worked a cash register.

The algorithm is easy to understand. You always give back the most coins of the highest denomination that you can.

As an example, lets say you need to give back 65 cents.

The highest denomination coin you can return is (in America), a quarter worth 25 cents. So you return 2 of those, adding up to 50 cents given back to the user so far. You cannot return any more quarters, since then you would be over 65 cents.

Now you have 15 cents left to return to the user, so the highest denomination coin you can give back is a dime. You give one dime back to the user, so you have returned 60 cents so far.

Now you have 5 cents left to return to the user, so the highest denomination coin you can give back is a nickel. You give a single nickel back to the user, and you now have returned a total of 65 cents.

How does this relate to my laundry woes?

I pop in 5 dimes, I get out two quarters. I pop in another 5 times, out comes another two quarters, I go off to put my laundry in the wash.

(This only works if you have a multitude of spare change lying around!)

The key to my success was not expecting what an ordinary user expects, but rather in using my understanding and training in the mathematics and engineering[1] disciplines to achieve an understanding of how to manipulate the world around me.

[1]I originally was intending on becoming a Computer Engineer and trained as such, even though I have switched over to Computer Science, I still retain much of my earlier learned behaviors and thinking patterns from Engineering, although those skills lie at an early stage of development.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: