|
You mention doing it for variable length chains, It requires hardly more effort than hard coding the length, something like find_match(X, P) :-
append([usd | _], [usd], X),
profit(X, P),
P > 1.
profit([A, B], P) :- exchange(A, B, P).
profit([A, B | T], P) :-
exchange(A, B, P1),
profit([B | T], P2),
P is P1 * P2.
# 1 ?- find_match(X, P).
# X = [usd, jpy, usd],
# P = 1.0040982 ;
# X = [usd, eur, jpy, usd],
# P = 1.0040882716200001 ;
# X = [usd, eur, btc, usd],
# P = 1.01209651875 ;
# X = [usd, btc, jpy, usd],
# P = 1.0025512896 ;
# X = [usd, eur, usd, jpy, usd],
# P = 1.003776175666278 .
|