Photonic realization of a quantum finite automaton