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

Home > Logic
Covert Quantity (Posted on 2013-04-02) Difficulty: 3 of 5
+---------+-------+
| 8 9 5 1 | R R   |       
+---------+-------+       
| 2 1 6 9 | R B   |     
+---------+-------+        
| 3 6 9 4 | R B   |        
+---------+-------+     
| 4 7 2 1 | R B   |        
+---------+-------+ 
| 1 2 3 7 | R R R |        
+---------+-------+
Each of the rows in the table given above indicates an attempt to find out the secret number. Each try has, in the column to the right, the letters R and B.

Each R indicates that this number has one digit in common with the secret number, but in a different position.

Each B indicates that this number has one digit in common with the secret number in the same position.

Determine the secret number.

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 2 of 4 |

DECLARE FUNCTION ans$ (a$, b$)
DATA 8951,rr, 2169,rb, 3694,rb, 4721,rb, 1237,rrr
FOR i = 1 TO 5
   READ try$(i), resp$(i)
NEXT

FOR n = 0 TO 9999
  cd$ = RIGHT$("00000" + LTRIM$(STR$(n)), 4)
     good = 1
     FOR i = 1 TO 5
       IF ans$(cd$, try$(i)) <> resp$(i) THEN good = 0: EXIT FOR
     NEXT
     IF good THEN PRINT cd$
NEXT

FUNCTION ans$ (a$, b$)
  an$ = "": x1$ = "": x2$ = ""
  FOR i = 1 TO LEN(b$)
    IF MID$(a$, i, 1) = MID$(b$, i, 1) THEN
      an$ = an$ + "b"
    ELSE
      x1$ = x1$ + MID$(a$, i, 1)
      x2$ = x2$ + MID$(b$, i, 1)
    END IF
  NEXT
    FOR i = 1 TO LEN(x2$)
      ix = INSTR(x1$, MID$(x2$, i, 1))
      IF ix > 0 THEN
        an$ = "r" + an$
        x1$ = LEFT$(x1$, ix - 1) + MID$(x1$, ix + 1)
      END IF
    NEXT
  ans$ = an$
END FUNCTION

finds

3719


  Posted by Charlie on 2013-04-02 16:01:17
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (1)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (6)
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