0% found this document useful (0 votes)
11 views

ASM2

Uploaded by

simon wong
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

ASM2

Uploaded by

simon wong
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

CSC3230 Tutorial

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

◼ (Use Prolog’s backtracking feature)


Constructing a single
solution for any valid n
◼ Say n = 8.

◼ 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

You might also like