VON#
Confessions of a code junkie
RSS
Monday, June 16, 2008
Programming Job Interview Challenge #8 Answer
I've been trying to keep up with the Job Interview line of posts over at dev102.com, but unfortunately I've been running out of time to do all of them. Anyway, this weeks question can be found
here
. Stop reading if you don't want the answer.
This problem can be solved using a Finite State Machine. The only thing you're going to store is the current state of the machine, once you reach the end of the machine, you'll alert. On initialization of the piping component, you'll build a finite state machine for the given alert sequence. Every time you are given a message you check what you should do with the state machine based on where you are currently at.
I was going to write out the code to do this, but it becomes a little tricky when you have repeating data in your alert sequence because if you get a message you're not expecting you don't necessarily want to reset the state machine to its initial state. For example, if the alert sequence was "A, A, A, A, B", and your input is "A, A, A, A, A, B", you don't want to reset the machine to the first state when you get that 5th A, you want it to stay in its current state.
Monday, June 16, 2008 - 12:48 PM CST -
Permalink
Comments [0]
-
Tags:
Stuff
Comments are closed.
All Content © 2008, Jon von Gillern
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Home
Tags
Blend
Design
IADNUG
Projects
Stuff
Tips and Tricks
Wishlist
Archive
August, 2008 (1)
July, 2008 (2)
June, 2008 (2)
May, 2008 (2)
March, 2008 (2)
February, 2008 (8)
January, 2008 (4)
December, 2007 (6)
November, 2007 (2)
Blogroll
Eric Sink
Javier Lozano
Jeff Atwood
Joel Spolsky
Nick Parker
Paul Graham
Scott Hanselman
Tim Gifford