http://blog.panqnik.pl/dev/sequence-points-in-c-cpp/
Best regards,
panqnik
>>The next step is to again start searching from the end of the sequence for the first member that is greater than or equal to the member pointed to by i.
The code for this quote is:
BidirectionalIterator j = last;
while (!(*i <*–j));
But this loop will continue if both members are equal.
So, the condition above should be:
… that is greater than the member pointed to by i …
Thank you.
]]>2. If there’s no handy hash, just generate an ordered list of numbers somewhat like an odometer with input chars ordered in ASCII is fine!
]]>Nice approach. On problems like this I have a tendency to go for the brute force first. A more elegant solution like yours is always more satisfying though.
- Mark
]]>The original problem can be solved by first listing the seven possible combinations of numbers in the range 1–9 such that no numbers are repeated and the sum is 17:
Exactly five of these must be included in the solution. Let's label the positions a–i, as Hugo did, and start with the diagonal c-e-g. Note that both c and g must occur in three different combinations, the candidates being 6, 7, 8 and 9. Using the fact that the figure is symmetric, let c < g. Then we have c = 6 or c = 7.
As there are no combinations containing both 5 and 6 or both 5 and 7, the only positions left for 5 are d and h. Again we use symmetry, and let d = 5. This in turn means a must be 3 or 4, and g must be 8 or 9.
There is only one combination containing 1, so 1 cannot be in any corner, and there are no combinations with both 8 and 9, so h and i cannot be 9. That leaves only e and h as possible positions for 1. Now if we were to let e = 1, we would get c = 7, g = 9, a = 3, and b would need to be 7, which is already taken by c. Therefore h = 1.
Then follows g = 9, i = 7, a = 3, c = 6, b = 8, f = 4 and e = 2.
]]>