pretty algorithm