Scanning a file
netvaibhav at gmail.com
netvaibhav at gmail.com
Sat Oct 29 15:35:32 EDT 2005
I think implementing a finite state automaton would be a good (best?)
solution. I have drawn a FSM for you (try viewing the following in
fixed width font). Just increment the count when you reach state 5.
<---------------|
| |
0 0 | 1 0 |0
-->[1]--->[2]--->[3]--->[4]--->[5]-|
^ | | ^ | | |
1| |<---| | | |1 |1
|_| 1 |_| | |
^ 0 | |
|---------------------|<-----|
If you don't understand FSM's, try getting a book on computational
theory (the book by Hopcroft & Ullman is great.)
Here you don't have special cases whether reading in blocks or reading
whole at once (as you only need one byte at a time).
Vaibhav
More information about the Python-list
mailing list