SWI-プロローグ-250
ああ、私はこれにあまりにも長い間費やしました。
o(A,B,A+B).
o(A,B,A-B).
o(A,B,A*B).
t([],0).
t([A,B|T],D):-t(T,Q),o(A,B,C),o(C,Q,D).
t([A|T],C):-t(T,Q),o(A,Q,C).
a(A):-t(A,B),n(C),B>C,retract(n(C)),assert(n(B)).
m(A):-assert(n(0)),\+p(A),n(R),R2 is R,write(R2).
p(A):-permutation([0|A],B),a(B),0=1.
コマンドラインから呼び出される(例):
> swipl -s filename.pl -g "m([1, 1, 1, 1, 1])" -t halt
6
(特に理由もなく、ゴルフの機能名のスペルが「トマトポット」であることは素晴らしいと思いました。)
ゴルフされていないバージョン:
% Possible operations
operation(Left, Right, Left + Right).
operation(Left, Right, Left - Right).
operation(Left, Right, Left * Right).
% Possible ways to transform
transform([], 0).
transform([A, B|T], D) :- transform(T, Q), operation(A, B, C), operation(C, Q, D).
transform([A|T], C) :- transform(T, Q), operation(A, Q, C).
% Throw the given array through every possible transformation and update the max
all_transforms(A) :- transform(A, B), n(C), B>C, retract(n(C)), assert(n(B)).
% Find all the permutations and transformations, then fail and continue execution.
prog(A) :- assert(n(0)), !, permutation([0|A], B), all_transforms(B), fail.
% End the program
finished :- n(R), write(R), nl, R2 is R, write(R2), nl.
% Run the program
main(A) :- ignore(prog(A)), finished.
説明:
- 引数として配列を受け取ります。
 
- 配列のすべての順列を取得します。
 
- 配列に追加する演算子の配列を見つけます。(これは動的プログラミングを介して行われ、最初の2つの要素を組み合わせた方が良いかどうかを確認します。)
 
- これを現在の最大値と比較してください。よければ、交換してください。
 
- プログラムにチェックを続けるように失敗したことを伝えますが、それを否定して(
ignoreまたはを使用して\+)述語全体を返しtrue、続行します。 
- 数値の代わりに述語の文字列が与えられているので、それを使用して割り当てて
isから記述します。