Basic algorithm that should solve within 10 minitutes