Scanning a file
David Rasmussen
david.rasmussen at gmx.net
Sat Oct 29 18:35:25 EDT 2005
netvaibhav at gmail.com wrote:
> 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.)
>
I already have that book. The above solution very slow in practice. None
of the solutions presented in this thread is nearly as fast as the
print file("filename", "rb").read().count("\x00\x00\x01\x00")
/David
More information about the Python-list
mailing list