Update code zigzag using algorithm