All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Logic
ABCD (2) (Posted on 2008-03-07) Difficulty: 3 of 5
Place one of the four letters A, B, C or D in each of the blue-coloured cells. No letter can be horizontally or vertically adjacent to itself. The yellow-coloured tables above and to the left of the grid indicate how many times each letter appears in that column or row.

This is an extended version of ABCD.

A

3

2

0

2

2

2

0

3

1

B

2

1

3

0

0

1

3

0

2

C

1

2

1

3

2

3

1

2

1

A

B

C

D

0

1

2

1

2

0

2

1

2

2

0

4

3

4

4

1

0

3

2

2

2

3

3

2

1

1

0

4

4

2

3

3

1

No Solution Yet Submitted by Josie Faulkner    
Rating: 4.1667 (6 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution (spoiler) | Comment 2 of 20 |

A little tweak of my computer solution to the first ABCD, by increasing the length of each of the 6 strings, was sufficient to solve this one:

DECLARE SUB permute (a$)
DECLARE FUNCTION noVadj! (a$, b$)
DECLARE FUNCTION noHadj! (s$)
DECLARE FUNCTION noColExcd! (s$)
DECLARE SUB addIn (s$)
DECLARE SUB subtOut (s$)
DIM SHARED aMax(9), aCt(9)
DIM SHARED bMax(9), bCt(9)
DIM SHARED cMax(9), cCt(9)
DIM SHARED dMax(9), dCt(9)

DATA 3,2,0,2,2,2,0,3,1
DATA 2,1,3,0,0,1,3,0,2
DATA 1,2,1,3,2,3,1,2,1
DATA 0,1,2,1,2,0,2,1,2

CLS

FOR i = 1 TO 9: READ aMax(i): NEXT
FOR i = 1 TO 9: READ bMax(i): NEXT
FOR i = 1 TO 9: READ cMax(i): NEXT
FOR i = 1 TO 9: READ dMax(i): NEXT

s1$ = "aaccccddd": h1$ = s1$
DO
 IF noHadj(s1$) THEN
  IF noColExcd(s1$) THEN
   addIn s1$

s2$ = "aaaabbbbc": h2$ = s2$
DO
 IF noHadj(s2$) THEN
  IF noColExcd(s2$) THEN
   IF noVadj(s1$, s2$) THEN
    addIn s2$


s3$ = "aaabbccdd": h3$ = s3$
DO
 IF noHadj(s3$) THEN
  IF noColExcd(s3$) THEN
   IF noVadj(s2$, s3$) THEN
    addIn s3$


s4$ = "aaabbbccd": h4$ = s4$
DO
 IF noHadj(s4$) THEN
  IF noColExcd(s4$) THEN
   IF noVadj(s3$, s4$) THEN
    addIn s4$


s5$ = "accccdddd": h5$ = s5$
DO
 IF noHadj(s5$) THEN
  IF noColExcd(s5$) THEN
   IF noVadj(s4$, s5$) THEN
    addIn s5$


s6$ = "aabbbcccd": h6$ = s6$
DO
 IF noHadj(s6$) THEN
  IF noColExcd(s6$) THEN
   IF noVadj(s5$, s6$) THEN
    addIn s6$

      col = solCt MOD 10
      row = solCt \ 10
      col = col * 8 + 1
      row = row * 8 + 1
      LOCATE row, col: PRINT s1$
      LOCATE row + 1, col: PRINT s2$
      LOCATE row + 2, col: PRINT s3$
      LOCATE row + 3, col: PRINT s4$
      LOCATE row + 4, col: PRINT s5$
      LOCATE row + 5, col: PRINT s6$
      solCt = solCt + 1


    subtOut s6$
   END IF
  END IF
 END IF
 permute s6$
LOOP UNTIL s6$ = h6$


    subtOut s5$
   END IF
  END IF
 END IF
 permute s5$
LOOP UNTIL s5$ = h5$


    subtOut s4$
   END IF
  END IF
 END IF
 permute s4$
LOOP UNTIL s4$ = h4$


    subtOut s3$
   END IF
  END IF
 END IF
 permute s3$
LOOP UNTIL s3$ = h3$


    subtOut s2$
   END IF
  END IF
 END IF
 permute s2$
LOOP UNTIL s2$ = h2$

   subtOut s1$
  END IF
 END IF
 permute s1$
LOOP UNTIL s1$ = h1$

PRINT : PRINT solCt

SUB addIn (s$)
 FOR i = 1 TO LEN(s$)
  SELECT CASE MID$(s$, i, 1)
    CASE "a"
     aCt(i) = aCt(i) + 1
    CASE "b"
     bCt(i) = bCt(i) + 1
    CASE "c"
     cCt(i) = cCt(i) + 1
    CASE "d"
     dCt(i) = dCt(i) + 1
  END SELECT
 NEXT
END SUB

FUNCTION noColExcd (s$)
 good = 1
 FOR i = 1 TO LEN(s$)
  x$ = MID$(s$, i, 1)
  SELECT CASE x$
   CASE "a"
     IF aCt(i) = aMax(i) THEN good = 0: EXIT FOR
   CASE "b"
     IF bCt(i) = bMax(i) THEN good = 0: EXIT FOR
   CASE "c"
     IF cCt(i) = cMax(i) THEN good = 0: EXIT FOR
   CASE "d"
     IF dCt(i) = dMax(i) THEN good = 0: EXIT FOR
  END SELECT
 NEXT
 noColExcd = good
END FUNCTION

FUNCTION noHadj (s$)
 good = 1
 FOR i = 1 TO LEN(s$) - 1
   IF MID$(s$, i, 1) = MID$(s$, i + 1, 1) THEN good = 0: EXIT FOR
 NEXT
 noHadj = good
END FUNCTION

FUNCTION noVadj (a$, b$)
 good = 1
 FOR i = 1 TO LEN(a$)
  IF MID$(a$, i, 1) = MID$(b$, i, 1) THEN good = 0: EXIT FOR
 NEXT
 noVadj = good
END FUNCTION

END SUB

DEFSNG A-Z
SUB subtOut (s$)
 FOR i = 1 TO LEN(s$)
  SELECT CASE MID$(s$, i, 1)
    CASE "a"
     aCt(i) = aCt(i) - 1
    CASE "b"
     bCt(i) = bCt(i) - 1
    CASE "c"
     cCt(i) = cCt(i) - 1
    CASE "d"
     dCt(i) = dCt(i) - 1
  END SELECT
 NEXT
END SUB

producing

acdcacdcd
babacabab
abdcabcda
babadcbac
cdcdcadcd
acbcdcbab

 


  Posted by Charlie on 2008-03-07 12:52:02
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information