how to calculate a pattern - Search