Lagford s Problem Moti Be-Ari Departmet of Sciece Teachig Weizma Istitute of Sciece http://www.weizma.ac.il/sci-tea/beari/ c 017 by Moti Be-Ari. This work is licesed uder the Creative Commos Attributio-ShareAlike 3.0 Uported Licese. To view a copy of this licese, visit http://creativecommos.org/liceses/by-sa/3.0/ or sed a letter to Creative Commos, 444 Castro Street, Suite 900, Moutai View, Califoria, 94041, USA.
The Defiitio of Lagford s problem Scottish mathematicia C. Dudley Lagford oticed that his so had arraged colored blocks i the followig arragemet: There is oe block betwee the two red blocks, two blocks betwee the blue blocks ad three blocks betwee the gree blocks. Therefore, the problem ca be expressed as follows: Give the bag of umbers {1,1,,,3,3}, ca they be arraged i a sequece such that for 1 i 3 there are i umbers betwee the two occurreces of i? 1 From the arragemet of the colored blocks, we see that a solutio is 3113. The geeralized problem is: Lagford s Problem L() Give the bag of umbers {1,1,,,3,3,...,,}, ca they be arraged i a sequece such that for 1 i there are i umbers betwee the two occurreces of i? Lagford s problem as a coverig problem Lagford s problem ca be posed usig arrays. For L(3), there are 6 colums, oe for each of the 3 umbers. The rows are defied by the defiitio of the problem: the two occurreces of k must have k umbers betwee them. It is easy to see that there are four possible placemets of 1, three of ad two of 3: 1 3 4 5 6 1 1 1 1 1 3 1 1 4 1 1 5 6 7 8 3 3 9 3 3 To solve the problem, we eed to select oe row for the 1 s i the sequece, oe row for the s ad oe row for the 3 s, such that if we stack these rows o top of each other, o colum cotais more tha oe umber: 1 A bag is like a set except that duplicate elemets may appear.
1 3 4 5 6 1 1 7 8 3 3 First, ote that row 9 is ot eeded because of symmetry: startig with row 9 just gives the reversal of the sequece obtaied by startig with row 8. Row 8 is the oly oe cotaiig 3 s so it must be chose ad the result is 3 3. Ay row with umbers i colums 1 ad 5 ca o loger be used, because oly oe umber ca be placed at each positio. Let us deote the permissible ad forbidde rows by 1,, 3, 4, 5, 6, 7, 8. Row 7 is the oly remaiig row cotaiig s so must be chose ad the result is 3 3. Deletig rows that ca o loger be used gives: 1,, 3, 4, 5, 6, 7, 8. Choosig the oly remaiig row, row, gives the solutio 3113. Furthermore, the aalysis has show that this is the oly solutio. Here is the array for L(4): Lagford s problem L(4) 1 3 4 5 6 7 8 1 1 1 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 8 9 10 11 1 3 3 13 3 3 14 3 3 15 3 3 16 4 4 17 4 4 18 4 4 We leave it to the reader to show that the oly solutio is 413143. 3
For which values of is Lagford s problem solvable? Theorem L() has a solutio if ad oly if = 4k or = 4k 1. We give two proofs of the forward implicatio based o Miller (014).. For the coverse, see Davies (1959). Proof 1 If the first occurrece of the umber k is at positio i k, the secod occurrece is at positio k + 1. The sum of the positios of all the umbers is: S = ( k + 1). But S, the sum of the positios, is simply 1 + + 3 + +, so: S = ( + 1) k =, usig the formula for the sum of a arithmetic progressio. Simplifyig: S = ( k + 1) = Equatig the two formulas for S gives: (k + 1) = ( + 3). ( + 3) = ( + 1), ad: i k = 1 ( ( + 1) ) ( + 3) = 3. 4 The left-had side is the sum of itegers (the positios), so it must be a iteger. The right-had side must also be a iteger. Whe is 3 3 divisible by 4? Factorig gives 3 = (3 1), so if is a multiple of 4, the product is divisible by 4. Whe is 3 1 divisible by 4? Ay iteger ca be expressed as = 4i + j for j = 0, 1,, 3. If 3 1 is divisible by 4, the so is 3(4i + j) 1 = 1i + 3j 1. Clearly, 1i is divisible by 4, ad it is easy to see that 3j 1 is divisible by 4 (for j = 0, 1,, 3) oly if j = 3, that is, = 4i + 3 = 4(i + 1) 1. 4
Proof Cosider the solutio for = 4: 1 3 4 5 6 7 8 4 1 3 1 4 3 The positios of the occurreces of 4 are 1 ad 6, ad the positios of the occurreces of are 5 ad 8. Oe positio is odd ad oe is eve. I the geeral case, if i is the positio of the first occurrece of a eve umber k, the the positio of the secod occurrece is i + k + 1. Sice k is eve, k + 1 is odd. Sice odd plus odd is eve ad eve plus odd is odd, oe of i, i + k + 1 must be odd ad the other eve. The positios of the occurreces of 1 are ad 4 ad the positios of the occurreces of 3 are 3 ad 7. For ay odd umber k, k + 1 is eve, so if i is eve, the i + k + 1 is eve, ad if i is odd, the i + k + 1 is odd. Obviously, the positios 1,,..., 1, cotai a equal umber of eve ad odd positios. Whe placig the two occurreces of a umber i the sequece, they take over two positios. Whe the sequece is complete, there must be a equal umber of eve ad odd positios take over. We use the term parity for the differece betwee the umber of eve ad odd positios take. Iitially, the parity is zero, ad if the problem has a solutio, the completed sequece also has a parity of zero. Whe the two occurreces of a eve umber is placed, they take over oe eve positio ad oe odd positio, so the parity remais the same. Whe the two occurreces of a odd umber is placed, the parity becomes + or, so we must be able to associate this pair with aother odd pair placed at positios that balace out the parity. I other words, there must be a eve umber of pairs of odd umbers, that is, there must be a eve umber of odd umbers i {1,..., }. The theorem claims that if there is a solutio, either = 4k or = 4k 1, ad if there is o solutio, the either = 4k or 4k 3. The proof is by iductio. For the base case, k = 1, it is easy to see that the sets {1} ad {1, } have o solutio; furthermore, they have a odd umber of odd umbers. For the sets {1,, 3} ad {1,, 3, 4}, we showed that they have solutios; furthermore, they have a eve umber of odd umbers. The iductive hypothesis is that solutios are possible for {1,..., 4k j}, k 1, j = 0, 1 (ad they have a eve umber of odd umbers), ad solutios are impossible for j =, 3 (ad they have a odd umber of odd umbers). Sice 4k + 1 is odd, addig it icreases the umber of odd umbers by oe, so there is o solutio. Similarly, addig 4k + 1, 4k + has o solutio sice 4k + 1 is odd ad 4k + is eve. Addig 4k + 1, 4k +, 4k + 3 or 4k + 1, 4k +, 4k + 3, 4k + 4 adds two odd umbers so there is still a eve umber of odd umbers ad there ca be a solutio. We have proved the claim for 4(k + 1) j ad by iductio the theorem holds for all 1. 5
SAT solvig I propositioal logic, a assigmet of true ad false to the atomic propositios of a formula A satisfies A if A evaluates to true. A SAT solver is a computer program that checks if a formula i CNF is satisfiable or usatisfiable. (For a overview of SAT solvig, see Be-Ari (01), Chapter 6.) Kuth (015) shows how solutios to Lagford s problem ca be foud by a SAT solver, by ecodig the array represetatio as a CNF formula. Let x i be true if row i is chose. For L(3), the followig clauses ecode that exactly oe of rows 1 4 cotaiig 1 must be chose: [x1,x,x3,x4], [~x1,~x], [~x1,~x3], [~x1,~x4], [~x,~x3], [~x,~x4], [~x3,~x4] The first clause ecodes that at least oe row must be chose. The ext clause ecodes that if row 1 is chose, x 1 = true, the row caot be chose, x = false, ad similarly for the other pairs of rows. Other clauses ecode that exactly oe of rows 5, 6, 7 must be chose ad that the row 8 must be chose. Clauses are also eeded to express the costraits o the colums. For example, colum 1 requires that exactly oe of rows 1, 5, 8 be chose: [x1,x5,x8], [~x1,~x5], [~x1,~x8], [~x5,~x8] Ruig a SAT solver returs the solutio that rows, 7 ad 8 should be chose: Satisfyig assigmets: [x1=0,x=1,x3=0,x4=0,x5=0,x6=0,x7=1,x8=1] CNF formulas for L(3) ad L(4) ca be foud i the archive for LearSAT, a SAT solver I developed for teachig. O my website http://www.weizma.ac.il/sci-tea/beari/ follow the liks for Software ad Learig Materials ad the LearSAT. Refereces M. Be-Ari. Mathematical Logic for Computer Sciece (Third Editio), Spriger, 01. R.O. Davies. O Lagford s problem (II), Mathematical Gazette, 43, 1959, 53-5. D.E. Kuth. The Art of Computer Programmig, Volume 4, Fascicle 6: Satisfiability, Pearso, 015. J.E. Miller. Lagford s Problem, Remixed, http://dialectrix.com/lagford.html, 014. 6