Back to General discussions forum
This is a travelling salesman problem with additional constraints.
Clive:
Thanks! I really enjoyed working on this one. This might have pushed my understanding of the [SPOILER] algorithm from "academic" to "intuitive". Thanks again.
Very interesting code / approach indeed, it looks to me almost like a mix of algorithm **** and algorithm ****.
- = ^ and + = |, and I need those for ternary numbers ...
Sorry, I'm trying to solve the problem. I tried double-checking all the calculations, even manually, but I always get values higher than expected. I'm attaching an example:
Input data: 11 3393 3260 4510 2230 3435 1510 2440 1246 4405 3741 4420 3139 2525 3811 1559 2202 468 627 370 3742 4757 3965 3551 2731 24 3442 2076 439 3411 369 4975 2390 2177 4376 3959 4952 3984 4023 772 1858 109 1864 1461 3702
Expected: 37864 Answer:42186
The example is calculated correctly.
Am I missing something? Thanks
You are missing a more sophisticated algorithm. Your latest attempt seems to employ a greedy approach (please correct me if I'm reading your code wrong!), which isn't quite sufficient for the purposes of this problem. Fortunately, this very site has a (different) problem that teaches an algorithm that would solve this correctly and (reasonably) quickly. :)
I can confirm that the answer of 37864 is correct. Not quite sure what you mean by "double-checking all the calculations"; since there are on the order of 12! possibilities to consider here, perhaps manual approach wouldn't quite suffice either.
Thanks for the suggestion. I realized I still have a lot to learn about algorithms.