Suppose the following fill-in-the-blanks exercise:

___ ___ and ___ ___ went to the ___.

Suppose the correct solution here is "John Smith and Mike Jones went to the pub". In other words: [John, Smith, Mike, Jones, pub].

But the following alternate solution should count as well - the persons are swapped but they are the correct people: [Mike, Jones, John, Smith, pub]. But, this next one definitely should not count as correct: [Mike, Smith, John, Jones, pub] because the names and surnames are mixed up.

OK. In order to make this work, I could hard-code two alternate orderings like so, and check the answers provided against them:

    [John, Smith, Mike, Jones, pub],
    [Mike, Jones, John, Smith, pub]

but this does not scale well. What if the sentence gets longer and their names and surnames appear again? What if another person joins? The number of combinations would grow quickly.

How should I approach this problem?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.