An algorithm of finding rules for a class of cellular automata