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

Home > Logic
Wrong Place, Right Place (Posted on 2003-11-17) Difficulty: 3 of 5
One person comes up to another person beside his bike. "Can I use your bike?" he asks. The person by the bike replies, "Only if you figure out the combination to my bike lock, which is made up of 4 different numbers from 1 through 8. You can guess 3 numbers."

He guessed 1235, 4721, and 3862. All three were answered with "One number in the combination is in the wrong place, and another is in the right place. The other two aren't in the combination."

The guesser was puzzled and asked "Is the number divisible by 7?" The person with the bike answered this question and after thinking for a while, the guesser told him the combination. What is the combination?

See The Solution Submitted by Gamer    
Rating: 3.3333 (9 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Solution - the original problem is fine as it is! | Comment 15 of 35 |
The answer is 2765. And I am very impressed by the guesser, who apparently did this in his head.

If one executes the following program (which determines which numbers satisfy the problem's criteria):


#include  "stdafx.h"
#include  <iostream.h>

int  CheckDiff(int  i,  int  j)
{
    int  numInRightPlace=0;
    int  numInWrongPlace=0;

    if  (  (i%10)  ==  (j%10)  )
        numInRightPlace  ++;
    if  (  ((i%100)/10)  ==  ((j%100)/10)  )
        numInRightPlace  ++;
    if  (  ((i%1000)/100)  ==  ((j%1000)/100)  )
        numInRightPlace  ++;
    if  (  (i/1000)  ==  (j/1000)  )
        numInRightPlace  ++;

    if  (  (i%10)  ==  ((j%100)/10)  )
        numInWrongPlace  ++;
    if  (  (i%10)  ==  ((j%1000)/100)  )
        numInWrongPlace  ++;
    if  (  (i%10)  ==  (j/1000)  )
        numInWrongPlace  ++;

    if  (  ((i%100)/10)  ==  (j%10)  )
        numInWrongPlace  ++;
    if  (  ((i%100)/10)  ==  ((j%1000)/100)  )
        numInWrongPlace  ++;
    if  (  ((i%100)/10)  ==  (j/1000)  )
        numInWrongPlace  ++;

    if  (  ((i%1000)/100)  ==  (j%10)  )
        numInWrongPlace  ++;
    if  (  ((i%1000)/100)  ==  ((j%100)/10)  )
        numInWrongPlace  ++;
    if  (  ((i%1000)/100)  ==  (j/1000)  )
        numInWrongPlace  ++;

    if  (  (i/1000)  ==  (j%10)  )
        numInWrongPlace  ++;
    if  (  (i/1000)  ==  ((j%100)/10)  )
        numInWrongPlace  ++;
    if  (  (i/1000)  ==  ((j%1000)/100)  )
        numInWrongPlace  ++;

    if  (numInRightPlace==1  &&  numInWrongPlace==1)
        return  (1);
    else
        return  (0);
}
        


int  main(int  argc,  char*  argv[])
{
    int  w,  x,  y,  z;

    int  check1  =  1235;
    int  check2  =  4721;
    int  check3  =  3862;

    for  (w  =  1;  w<9;  w++)
        for  (x  =  1;  x<9;  x++)
            for  (y  =  1;  y<9;  y++)
                for  (z  =  1;  z<9;  z++)
                    if  (  (w!=x)  &&  (w!=y)  &&  (w!=z)  &&  (x!=y)  &&  (x!=z)  &&  (y!=z)  )
                    {
                        int  num  =  w*1000+x*100+y*10+z;
                        if  (  CheckDiff(check1,  num)  &&
                                  CheckDiff(check2,  num)  &&
                                  CheckDiff(check3,num)  )
                            cout  <<  num  <<  \"    mod  7  =  \"  <<  num%7  <<  endl;
                    }

    return  0;
}

the output from this program is:

1763 mod 7 = 6
2765 mod 7 = 0
7825 mod 7 = 6
7831 mod 7 = 5

The last question (about divisibility by seven) groups the results into two sets. One set contains {2765}, and the other contains {1763, 7825, 7831}.

Since the guesser was able to identify the answer based on this question, it must be the set containing only one member. So the answer to the question was "yes, it is divisible by seven".

And the answer to the riddle is: 2765


  Posted by SilverKnight on 2003-11-18 08:19:40
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