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

Home > Logic
Family Occupations (Posted on 2013-06-17) Difficulty: 3 of 5
One of the four people - Mr. Brown, his wife Monika, their son Mandy and their daughter Cindy - is a singer and another is a dancer.
  1. If the singer and the dancer are the same sex, then the dancer is older than the singer.
  2. If neither the singer nor the dancer is the parent of the other, then the singer is older than the dancer.
  3. If the singer is a man, then the singer and the dancer are the same age.
  4. If the singer and the dancer are of opposite sex then the man is older than the woman.
Whose occupation can you deduce with absolute certainty?

See The Solution Submitted by K Sengupta    
Rating: 4.0000 (2 votes)

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

DECLARE SUB permute (a$)
CLS
' order MrBrown, wife Monika, son Mandy, daughter Cindy
occ$ = "  sd"

ho$ = occ$
DO
 FOR agetype = 1 TO 3 '  1=singer younger; 2=equal ages; 3= singer older
  good = 1
  sing = INSTR(occ$, "s")
  dance = INSTR(occ$, "d")
  IF sing MOD 2 = dance MOD 2 AND agetype <> 1 THEN good = 0
  IF (sing < 3) = (dance < 3) AND agetype <> 3 THEN good = 0
  IF sing MOD 2 = 1 AND agetype <> 2 THEN good = 0
  IF sing MOD 2 = 1 THEN manage = agetype
  IF dance MOD 2 = 1 THEN manage = 4 - agetype

  IF sing MOD 2 <> dance MOD 2 AND manage <> 3 THEN good = 0

  IF sing < 3 AND dance > 2 AND agetype <> 3 THEN good = 0
  IF dance < 3 AND sing > 2 AND agetype <> 1 THEN good = 0

  IF good THEN PRINT ":"; occ$; ":"; agetype
 NEXT agetype
 permute occ$
LOOP UNTIL occ$ = ho$

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

finds

: d s: 1
:d  s: 1

Meaning that the daughter, Cindy, is the singer and either of the parents is the dancer.


  Posted by Charlie on 2013-06-17 18:23:07
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 (16)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

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