Algorithm in less lines