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

Home > Logic
All the Marbles (Posted on 2005-04-22) Difficulty: 3 of 5
Five neighborhood children (two of whom- Henry and Kirby- are boys, and three of whom-Iris, Josephine, and Louise-are girls) are counting their marbles. Each child is a different age (7 through 11 years) and has at least one but no more than 5 of each of aggies, alleys, immies, mibs, and steelies. No two children have the same number of the same type of marble. From the information provided determine each child's age and the number of each type of marble in his or her collection.

1. The five children are Josephine, the 10 year old, the child who owns 2 alleys, the girl who has 3 immies, and the child who has 4 mibs.
2. Each child owns exactly 15 marbles.
3. The boy who has five steelies is older than at least one other child.
4. The number of steelies in one child's collection is exactly half his or her age.
5. The 11 year old child has one aggie.
6. The only types of marble of which Iris has an even number are immies and mibs.
7. One of the boys has 5 aggies.
8. Kirby doesn't own 2 of any type of marble.
9. The child with 3 immies has fewer than 3 mibs and fewer than 3 steelies.
10. One child has 3 aggies, 5 immies, and 1 steelie.
11. Each of at least 2 children has exactly twice as many alleys as immies.

See The Solution Submitted by Catherine    
Rating: 4.3077 (13 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Another program | Comment 11 of 18 |
(In reply to In response to overwhelming demand...... by Penny)

This one does take age into consideration:

DECLARE SUB permute (a$)
age$ = "789ab"  ' order hkijl
ag$ = "12345"
al$ = "12345"
im$ = "12345"
mi$ = "12345"
st$ = "12345"
OPEN "allmarbl.txt" FOR OUTPUT AS #2
FOR agen = 1 TO 120
 PRINT agen;
 IF MID$(age$, 4, 1) <> "a" THEN
  FOR aln = 1 TO 120
    ix = INSTR(al$, "2")
    IF ix <> 4 AND ix <> 2 AND MID$(age$, ix, 1) <> "a" THEN
     FOR imn = 1 TO 120
      ix = INSTR(im$, "5")
      im5 = ix
      im1 = INSTR(im$, "1")
      im2 = INSTR(im$, "2")
      IF MID$(al$, im1, 1) = "2" AND MID$(al$, im2, 1) = "4" THEN good = 1:  ELSE good = 0
      ix = INSTR(im$, "3")
      im3 = ix
      IF (ix = 3 OR ix = 5) AND im2 <> 2 AND good = 1 THEN
       IF MID$(age$, ix, 1) <> "a" AND MID$(al$, ix, 1) <> "2" THEN
        FOR min = 1 TO 120
         ix = INSTR(mi$, "4")
         IF MID$(age$, ix, 1) <> "a" AND MID$(al$, ix, 1) <> "2" AND MID$(im$, ix, 1) <> "3" AND MID$(mi$, 2, 1) <> "2" AND MID$(mi$, im3, 1) < "3" THEN
          FOR agn = 1 TO 120
            ix = INSTR(ag$, "5")
            IF ix < 3 THEN good = 1:  ELSE good = 0
            IF MID$(ag$, 2, 1) = "2" THEN good = 0
            IF MID$(ag$, im5, 1) <> "3" THEN good = 0
            ix = INSTR(ag$, "1")
            IF MID$(age$, ix, 1) = "b" AND good = 1 THEN
              FOR stn = 1 TO 120
               good = 0
               FOR child = 1 TO 5
                 IF MID$(age$, child, 1) = "8" AND MID$(st$, child, 1) = "4" THEN good = 1
                 IF MID$(age$, child, 1) = "a" AND MID$(st$, child, 1) = "5" THEN good = 1
               NEXT child
               IF MID$(st$, 2, 1) = "2" THEN good = 0
               IF MID$(st$, im3, 1) > "3" THEN good = 0
               IF MID$(st$, im5, 1) > "1" THEN good = 0
               IF INSTR("24", MID$(im$, 3, 1)) = 0 THEN good = 0
               IF INSTR("24", MID$(mi$, 3, 1)) = 0 THEN good = 0
               IF INSTR("24", MID$(ag$, 3, 1)) > 0 THEN good = 0
               IF INSTR("24", MID$(al$, 3, 1)) > 0 THEN good = 0
               IF INSTR("24", MID$(st$, 3, 1)) > 0 THEN good = 0
               ix = INSTR(st$, "5")
               IF ix < 3 AND MID$(age$, ix, 1) > "7" AND good = 1 THEN
                FOR child = 1 TO 5
                 tot = VAL(MID$(ag$, child, 1)) + VAL(MID$(al$, child, 1)) + VAL(MID$(im$, child, 1)) + VAL(MID$(mi$, child, 1)) + VAL(MID$(st$, child, 1))
                 IF tot <> 15 THEN good = 0: EXIT FOR
                NEXT child
                IF good THEN
                  PRINT : PRINT age$: PRINT ag$: PRINT al$: PRINT im$: PRINT mi$: PRINT st$
                  PRINT #2, : PRINT #2, age$: PRINT #2, ag$: PRINT #2, al$: PRINT #2, im$: PRINT #2, mi$: PRINT #2, st$
                END IF
               END IF
               permute st$
              NEXT stn
            END IF
            permute ag$
          NEXT agn
         END IF
         permute mi$
        NEXT min
       END IF
      END IF
      permute im$
     NEXT imn
    END IF
    permute al$
  NEXT aln
 END IF
 permute age$
NEXT agen

CLOSE

SUB permute (a$)
DEFINT A-Z
 x$ = ""
 FOR i = LEN(a$) TO 1 STEP -1
  l$ = x$
  x$ = MID$(a$, i, 1)
  IF x$ < l$ THEN EXIT FOR
 NEXT

 IF i = 0 THEN
  FOR j = 1 TO LEN(a$) \ 2
   x$ = MID$(a$, j, 1)
   MID$(a$, j, 1) = MID$(a$, LEN(a$) - j + 1, 1)
   MID$(a$, LEN(a$) - j + 1, 1) = x$
  NEXT
 ELSE
  FOR j = LEN(a$) TO i + 1 STEP -1
   IF MID$(a$, j, 1) > x$ THEN EXIT FOR
  NEXT
  MID$(a$, i, 1) = MID$(a$, j, 1)
  MID$(a$, j, 1) = x$
  FOR j = 1 TO (LEN(a$) - i) \ 2
   x$ = MID$(a$, i + j, 1)
   MID$(a$, i + j, 1) = MID$(a$, LEN(a$) - j + 1, 1)
   MID$(a$, LEN(a$) - j + 1, 1) = x$
  NEXT
 END IF

END SUB

giving the answer as:

9ab87
53124
21345
15423
25431
51342

where the sequence is Henry, Kirby, Iris, Josephine and Louise.

The first row is for age, where a represents 10 and b represents 11. Subsequent rows show number of aggies, alleys, immies, migs and steelies.


  Posted by Charlie on 2005-04-23 23:28:10
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 (7)
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