ASM2
ASM2
Assignment 2
Langford’s Problem
◼ (2,n)-Langford’s problem
◼ Put {1, 1, 2, 2, 3, 3, …, k, k, …, n, n}
in an order that any pair (k, k) are
separated by k digits
◼ Example: (2,4) instance
◼ 23421314
◼ 41312432
Constructing a single
solution for any valid n
◼ Say n = 8.
◼ 1122334455667788
◼ ________________
Constructing a single
solution for any valid n
◼ Say n = 8.
◼ 1122334455667788
◼ ________________
Constructing a single
solution for any valid n
◼ Say n = 8.
◼ 11223345678
◼ 45678___________
Constructing a single
solution for any valid n
◼ Say n = 8.
◼ 1122335678
◼ 456784__________
Constructing a single
solution for any valid n
◼ Say n = 8.
◼ 112233678
◼ 456784_5________
Constructing a single
solution for any valid n
◼ Say n = 8.
◼ 112233
◼ 456784_5_6_7_8__
Constructing a single
solution for any valid n
◼ Say n = 8.
◼ 112233
◼ 456784_5_6_7_8__
Constructing a single
solution for any valid n
◼ Say n = 8.
◼ 1133
◼ 456784_5_6_728_2
Constructing a single
solution for any valid n
◼ Say n = 8.
◼ 1133
◼ 456784_5_6_728_2
◼ 1
◼ 456784 35163728_2
◼ BACKTRACK … !!!
Constructing a single
solution for any valid n
◼ Say n = 8.
◼ 4567841516372832
Algorithm
◼ Enter, in sequence from left to right,
the number from n/2 (round up if n
is odd) to n, and add the second of
each pair.
◼ Enter into every other space, in
sequence from right to left, the even
numbers from 2 to (n/2)-2, and add
the second of each pair.
Algorithm
◼ In the region to the right-handed
number n, enter, in sequence from
right to left, as many alternate odd
numbers, commencing with 3 and
proceeding with 7, 11, 15, 19, … as
possible.
◼ Enter the remaining odd number.
Reference
◼ John E. Miller, Langford’s Problem,
http://www.lclark.edu/~miller/langf
ord.html