New puzzle function improved efficiency