For Programmers: Free Programming Magazines  


Home > Archive > Prolog > December 2004 > small puzzles









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author small puzzles
el_bandido@nospam.com

2004-12-07, 4:13 am

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
--
KBoy

2004-12-07, 4:13 am

el_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'.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com