Brute-force solved euler 14 but need more elegant solution because this takes ~3 minutes to complete