Skip to main content
added 14 characters in body
Source Link
orlp
  • 39.2k
  • 7
  • 81
  • 195

SWI-Prolog, 62 4747 41 bytes

*(X,Y)X*Y:-X+Y;Y+X;X==Y.
?(X,?Y):-not(X*Y),X*Z,Y*Z.

Prolog isn't too often useful, but when it is it's just beautiful. We'll use a+b to notate that a is friends with b, a*b that a knows b and a?b that b should be suggested to a or not. The first line simply says that X*Y is true if either X+Y, Y+X or X == Y is true. This implements the symmetry of knowing eachother. Asking if there should be a suggestion is incredibly simple. We just ask if there is a Z such that X*Y is false and X*Z and Y*Z is true. Exactly as described in the challenge.

If you save this as a file (e.g. friends.pl) and open SWI-Prolog with this file (prolog -l friends.pl) you get dropped into a REPL.

You can assert friendships like this:

assert('a' + 'b').
assert('a' + 'c').
assert('b' + 'd').

You can check if people know eachother or suggestion should be made:

'a'*'b'.
'a'?'d'.

SWI-Prolog, 62 47 bytes

*(X,Y):-X+Y;Y+X;X==Y.
?(X,Y):-not(X*Y),X*Z,Y*Z.

Prolog isn't too often useful, but when it is it's just beautiful. We'll use a+b to notate that a is friends with b, a*b that a knows b and a?b that b should be suggested to a or not. The first line simply says that X*Y is true if either X+Y, Y+X or X == Y is true. This implements the symmetry of knowing eachother. Asking if there should be a suggestion is incredibly simple. We just ask if there is a Z such that X*Y is false and X*Z and Y*Z is true. Exactly as described in the challenge.

If you save this as a file (e.g. friends.pl) and open SWI-Prolog with this file (prolog -l friends.pl) you get dropped into a REPL.

You can assert friendships like this:

assert('a' + 'b').
assert('a' + 'c').
assert('b' + 'd').

You can check if people know eachother or suggestion should be made:

'a'*'b'.
'a'?'d'.

SWI-Prolog, 62 47 41 bytes

X*Y:-X+Y;Y+X;X==Y.
X?Y:-not(X*Y),X*Z,Y*Z.

Prolog isn't too often useful, but when it is it's just beautiful. We'll use a+b to notate that a is friends with b, a*b that a knows b and a?b that b should be suggested to a or not. The first line simply says that X*Y is true if either X+Y, Y+X or X == Y is true. This implements the symmetry of knowing eachother. Asking if there should be a suggestion is incredibly simple. We just ask if there is a Z such that X*Y is false and X*Z and Y*Z is true. Exactly as described in the challenge.

If you save this as a file (e.g. friends.pl) and open SWI-Prolog with this file (prolog -l friends.pl) you get dropped into a REPL.

You can assert friendships like this:

assert('a' + 'b').
assert('a' + 'c').
assert('b' + 'd').

You can check if people know eachother or suggestion should be made:

'a'*'b'.
'a'?'d'.
added 102 characters in body
Source Link
orlp
  • 39.2k
  • 7
  • 81
  • 195

SWI-Prolog, 6262 47 bytes

k*(X,Y):-f(X,Y);f(Y,X);X==YX+Y;Y+X;X==Y.
s?(X,Y):-not(k(X,Y)),k(X,ZX*Y),k(YX*Z,Z)Y*Z.

Prolog isn't too often useful, but when it is it's just beautiful. We'll use a+b to notate that a is friends with b, a*b that a knows b and a?b that b should be suggested to a or not. The first line simply says that k(X, Y)X*Y is true if either f(X, Y)X+Y, f(Y, X)Y+X or X == Y is true. This implements the symmetry of knowing eachother. Asking if there should be a suggestion is incredibly simple. We just ask if there is a Z such that k(X, Y)X*Y is false and k(X, Z)X*Z and k(Y, Z)Y*Z is true. Exactly as described in the challenge.

If you save this as a file (e.g. friends.pl) and open SWI-Prolog with this file (prolog -l friends.pl) you get dropped into a REPL.

You can assert friendships like this:

assert(f('a', + 'b')).
assert(f('a', + 'c')).
assert(f('b', + 'd')).

You can check if people know eachother or suggestion should be made:

k('a', 'b')'a'*'b'.
s('a', ?'d').

SWI-Prolog, 62 bytes

k(X,Y):-f(X,Y);f(Y,X);X==Y.
s(X,Y):-not(k(X,Y)),k(X,Z),k(Y,Z).

Prolog isn't too often useful, but when it is it's just beautiful. The first line simply says that k(X, Y) is true if either f(X, Y), f(Y, X) or X == Y is true. This implements the symmetry of knowing eachother. Asking if there should be a suggestion is incredibly simple. We just ask if there is a Z such that k(X, Y) is false and k(X, Z) and k(Y, Z) is true. Exactly as described in the challenge.

If you save this as a file (e.g. friends.pl) and open SWI-Prolog with this file (prolog -l friends.pl) you get dropped into a REPL.

You can assert friendships like this:

assert(f('a', 'b')).
assert(f('a', 'c')).
assert(f('b', 'd')).

You can check if people know eachother or suggestion should be made:

k('a', 'b').
s('a', 'd').

SWI-Prolog, 62 47 bytes

*(X,Y):-X+Y;Y+X;X==Y.
?(X,Y):-not(X*Y),X*Z,Y*Z.

Prolog isn't too often useful, but when it is it's just beautiful. We'll use a+b to notate that a is friends with b, a*b that a knows b and a?b that b should be suggested to a or not. The first line simply says that X*Y is true if either X+Y, Y+X or X == Y is true. This implements the symmetry of knowing eachother. Asking if there should be a suggestion is incredibly simple. We just ask if there is a Z such that X*Y is false and X*Z and Y*Z is true. Exactly as described in the challenge.

If you save this as a file (e.g. friends.pl) and open SWI-Prolog with this file (prolog -l friends.pl) you get dropped into a REPL.

You can assert friendships like this:

assert('a' + 'b').
assert('a' + 'c').
assert('b' + 'd').

You can check if people know eachother or suggestion should be made:

'a'*'b'.
'a'?'d'.
Source Link
orlp
  • 39.2k
  • 7
  • 81
  • 195

SWI-Prolog, 62 bytes

k(X,Y):-f(X,Y);f(Y,X);X==Y.
s(X,Y):-not(k(X,Y)),k(X,Z),k(Y,Z).

Prolog isn't too often useful, but when it is it's just beautiful. The first line simply says that k(X, Y) is true if either f(X, Y), f(Y, X) or X == Y is true. This implements the symmetry of knowing eachother. Asking if there should be a suggestion is incredibly simple. We just ask if there is a Z such that k(X, Y) is false and k(X, Z) and k(Y, Z) is true. Exactly as described in the challenge.

If you save this as a file (e.g. friends.pl) and open SWI-Prolog with this file (prolog -l friends.pl) you get dropped into a REPL.

You can assert friendships like this:

assert(f('a', 'b')).
assert(f('a', 'c')).
assert(f('b', 'd')).

You can check if people know eachother or suggestion should be made:

k('a', 'b').
s('a', 'd').