2 ms·
To find the missing constraints, you can try asking what's wrong with the list [1, 2]. You might imagine trying to have an argument with a person trying to sel
by computerphage 6y ago
To find the missing constraints, you can try asking what's wrong with the list [1, 2].
You might imagine trying to have an argument with a person trying to sell you a list sorter. The salesman is just going on and on about how "but look, each element of the list I gave you is in the right order! So you should buy my very nice list sorter!". I would want to yell "but you didn't include any of the numbers from the input list! You just forgot about 7, 3, and 5."
So, another formal constraint might be something like this:
for each element, i, in the input list, the element i must be in the output list.
Then, you might again try putting in [7,3,5] and get back a list like this: [1,2,3,4,5,6,7]. Again, imagine arguing with the pushy salesman. The salesman says "Look, you wanted a list with the numbers 7, 3, and 5, and you wanted a list in order, this is both of those things, so you have to pay me for my fine list-sorter now!" And again, I would want to object and say something like "but wait a second, I want ONLY the numbers that I gave you in the input list in the output list!". So, you end up with something like:
for each element, j, of the output list, the element j must be in the input list.
Now, you try putting in [7,3,5] again. What's the worst thing that might come out the other end that's still following all of these 3 rules? Can you spot the next problem?