% FILE:  crypto_2345_short.pro of crypto_xps
% TYPE:  Prolog soource
% LINE:  Essential Crypto problem solver -- the short way
% DATE:  October 2019

%-----------------------------------------------------------------
% LOAD FILES

:- consult('crypto_234_short.pro').

% -----------------------------------------------------------------
% ORDER 5 CRYPTO PROBLEM SOLVER

crypto( N1, N2, N3, N4, N5, G ,Expr ) :-
  comb( set(N1,N2,N3,N4,N5), comb(A,B), extras(C,D,E) ),
  crypto( A, B, SG, SGE ),
  crypto( C, D, E, SG, G, UGE ),
  substitute( SGE, SG, UGE, Expr ).

%-----------------------------------------------------------------
% ORDER 5 CRYPTO TESTING

test5(0).
test5(N) :-
  demo5,
  NM1 is N-1,
  test5(NM1).

demo5 :-
  generate5(N1,N2,N3,N4,N5,G),
  display5(N1,N2,N3,N4,N5,G),
  solve5(N1,N2,N3,N4,N5,G).

generate5(N1,N2,N3,N4,N5,G) :-
  random(0,6,N1),
  random(0,6,N2),
  random(0,6,N3),
  random(0,6,N4),
  random(0,6,N5),
  random(0,6,G).

display5(N1,N2,N3,N4,N5,G) :-
  write(problem(numbers(N1,N2,N3,N4,N5),goal(G))), write(' --> ').

solve5(N1,N2,N3,N4,N5,G) :-
  crypto(N1,N2,N3,N4,N5,G,X),
  write(X),nl.
solve5(_,_,_,_,_,_) :-
  write('no solution'),nl.