Here's one approach:

s

p

o

i

l

e

r



s

p

a

c

e


f

o

r


p

e

o

p

l

e


w

h

o


a

r

e


n

o

t


r

e

a

d

y


t

o


s

e

e


s

o

l

u

t

i

o

n

s

.

.

.


EMPTY=: i.0 4
isKnave=: 1 0,2+,
isKnight=:1 1,2+,
isSame=: 1,2+,
isDiff=: 0,2+,
num=: _1+>./@,
enum=: 2 #:@i.@^ num
solve=: enum #~ [: */ ] =/@:{"1/ 0,.1,.enum

Example use:

   solve (0 isSame 2 3),(1 isKnight 2),(0 isKnight 1),EMPTY
0 0 0 1
1 1 1 1

This result means that there are two solutions for this example.  One
solution is that all four people are knights, the other solution is
that 0, 1 and 2 are knaves while 3 is a knight.

People are identified by index numbers, answers are represented as bit
indices (for each index: 0 if the person would be a knave, 1 if they
would be a knight).

The left argument to the isFoo verbs is the person making the
statement, the right argument is the person (or pair) being critiqued.

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to