Pop Quiz: Traffic Lights

As a follow up to yesterday's Power Calc article, which, in passing, mentioned state machines, I pose the following question to you:

How many states are there for a typical traffic signal controlling two perpendicular streets?

There's three light colors -- red, yellow, and green -- so that means there must be three states right?

Or, could it be that since there are twelve lights -- two streets, each street running in two directions, one set of three colored lights visible in each direction (2*2*3=12) -- that there are twelve states?

Or, noting, that opposite directions always have the same colors at the same time, perhaps that should be six states?

The correct answer is, in fact, none of the above....

See full post...

Power Toy Calc

Recently I worked with a group of people almost all of who used Excel to perform day to day calculations while programming. I, for one, seem hardwired to booting up Visual C and either using the compiler or the debugger, but surely there's a better way.

I've used the power calc in passing but never realized before today that, using it, you can create both variables and simple custom functions, even preserving them across sessions should you want to. For that occasional unit conversion -- feet to meters for instance -- power calc also has several common conversions built in ( That is, of course, assuming you have some aversion to Google's more complete search conversions. )

I like it best in "Advanced" mode with the "Samples" checked off ( both accessible via the "View" Menu) and the Graph rolled up. This turns off the visual keypad ( who uses the mouse to enter numbers anyway? ) and shows you both your input history and a listing of all currently registered variables.

Here's a screenshot:

power toy calc

Everything that shows up in the history box, is exactly as typed from the input line.
10 [lb->oz] x=5 f(y)=x+y f(7) x=2 f(7)
To be honest, I kind of hate the History mechanism; it feels pretty unpolished. I'd rather the input be at the top-left -- the graph and variables panels on the right -- and that the history work by simply dropping me to the next line ( thus mirroring the behavior of every other text entry app in the world ). The result of the calculation could simply be appended to the line where appropriate (eg. 5+4, becomes, after pressing enter: 5+4=9 ). A separate box ( at the upper right? ) for the current result to assist in cut and paste would probably be another good addition.

I'm sure there's good open-source and commercial alternatives out there. What do you use?

As a side note: for a somewhat interesting look at the Visual Basic Calculator's state machine bugs see the "Who moved my state" article or Miro Samek's Practical Statecharts book.
See full post...