card trick algorithm