right algorithm, but too slow to get an answer, TODO