my useful algorithm