Code Comments
Programming Forum and web based access to our favorite programming groups.Hello, I've got two puzzles to solve of which one I managed somehow but the other I cannot seem to even get started. Puzzle 1 -------- Given a combination lock with 7 positions (A,B,C,D,E,F,G) of which all can represent numbers from 1 to 5, we remember following: C has to be on pos 2. D has to be on pos 4. E has to be on pos 3. G has to be on pos 2. F is not to be on pos 4. A is not to be on either pos 1, 2 or 4. B is not to be on either pos 1, 4 or 5. If A is on pos 5, F has to be on 1. If B is on pos 2, D has to be on 1. If D is on pos 4, A is not to be on pos 3. My solution to puzzle 1 ----------------------- num(1). num(2). num(3). num(4). num(5). combination(A,B,C,D,E,F,G):- num(A), A \= 1, A \= 2, A \= 4, num(B), B \= 1, B \= 4, B \= 5, num(C), C is 2, num(D), D is 4, num(E), E is 3, num(F), F \= 4, num(G), G is 2, ((A is 5,F is 1);(A \= 5)), ((B is 2,D is 1);(B \= 2)), ((D is 4,A \= 3);(D \= 4)). I'm sure there is a better one, could anyone maybe point me to it? Puzzle 2 -------- A family is about to visit their friends. They are a bit complicated as to who is going. The problematic part of the family consist of Mr. Funky, Mrs. Funky, the kids Marc and Joseline and grandpa Funky. The rules are as follows: If Mrs. Funky goes, his wife goes as well. At least one of the kids Marc and Joseline will be going. If Marc goes, grandpa Funky will be going. If Mrs. Funky goes, grandpa Funky will not be going. If Joseline goes, Mr. Funky and Marcel will be going. Who will be visiting their friends? I'd be happy to get some pointers or even a solution. eb --
Post Follow-up to this messageel_bandido@nospam.com wrote: > Hello, > > I've got two puzzles to solve of which one I managed somehow but the > other I cannot seem to even get started. > > > Puzzle 1 > -------- > Given a combination lock with 7 positions (A,B,C,D,E,F,G) of which all > can represent numbers from 1 to 5, we remember following: > > C has to be on pos 2. > D has to be on pos 4. > E has to be on pos 3. > G has to be on pos 2. > F is not to be on pos 4. > A is not to be on either pos 1, 2 or 4. > B is not to be on either pos 1, 4 or 5. > If A is on pos 5, F has to be on 1. > If B is on pos 2, D has to be on 1. > If D is on pos 4, A is not to be on pos 3. > > My solution to puzzle 1 > ----------------------- > num(1). > num(2). > num(3). > num(4). > num(5). > > combination(A,B,C,D,E,F,G):- > num(A), A \= 1, A \= 2, A \= 4, > num(B), B \= 1, B \= 4, B \= 5, > num(C), C is 2, > num(D), D is 4, > num(E), E is 3, > num(F), F \= 4, > num(G), G is 2, > ((A is 5,F is 1);(A \= 5)), > ((B is 2,D is 1);(B \= 2)), > ((D is 4,A \= 3);(D \= 4)). > > I'm sure there is a better one, could anyone maybe point me to it? > > > Puzzle 2 > -------- > A family is about to visit their friends. They are a bit complicated as > to who is going. The problematic part of the family consist of Mr. > Funky, Mrs. Funky, the kids Marc and Joseline and grandpa Funky. The > rules are as follows: > > If Mrs. Funky goes, his wife goes as well. > At least one of the kids Marc and Joseline will be going. > If Marc goes, grandpa Funky will be going. > If Mrs. Funky goes, grandpa Funky will not be going. > If Joseline goes, Mr. Funky and Marcel will be going. > > Who will be visiting their friends? > > I'd be happy to get some pointers or even a solution. > eb I think a good tip for this problem is: Advice: Create a variable for each member of the family, which can have the constant values 'yes' or 'no'.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.