An M-digit non-negative integer n is a Langford Pairing of length M if it has the following
Fantastic news! We've Found the answer you've been seeking!
Question:
An M-digit non-negative integer n is a Langford Pairing of length M if it has the following properties:
- It has an even number of digits (so M is even, although the number n does not have to be even).
- It contains 2 copies of each of the digits from 1 to M/2.
- Its two 1s have one digit between them, its two 2's have two digits between them, etc. In general, the two instances of a digit k have k digits between them.
For example, n=41312432 is a Langford pairing of length M=8, because the two 1's have one digit between them (a three). The two 2's have two digits between them (a four and a three), etc.
With this in mind, write the function isLangfordPairing(n) which takes an integer n, and returns True if it is a Langford Pairing, and False otherwise.
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date: