implemented circuit simulation example from Programming in Scala 2nd Ed.