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?


1 Answer 1


We could use [[John, Smith], [Mike, Jones], pub]. Therefore, we know [John, Smith] should be treated as one, as well as [Mike, Jones].

We would also know to only use these where there are two blanks in a row, when they obey part of speech rules, and not to reverse the order.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.