use c++ 11 syntax in for loops
use std::distance instead of direct subtraction for clarity
add test for some simple (integer) state simulation