/* From 11 to 25 in Picat. The Bonus problem from "Can you solve the giant cat army riddle? - Dan Finkel" https://www.youtube.com/watch?v=YeMVoJKn1Tg&feature=youtu.be @4:35 """ Get from 11 to 25 Operations available: - x*2 - x-3 """ This is the shortest and unique solutions (length 8), [11,8,5,10,7,14,28,25] Cf two_buttons_problem.pi This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. import cp. main => go. op1(X,Y) => Y = X*2. op2(X,Y) => Y = X-3. go ?=> member(Len,4..100), println(len=Len), L = new_list(Len), L[1] = 11, L[Len] = 25, foreach(I in 2..Len) ( op1(L[I-1],L[I]) ; op2(L[I-1],L[I]) ) end, println(L), % fail, nl. go => true. go2 ?=> _ = random2(), StartVal = random() mod 100, EndVal = random() mod 100, StartVal != EndVal, println([start=StartVal,end=EndVal]), OpList1 = [*,//], Op1 = OpList1[1+random() mod 2], OpList2 = [+,-], Op2 = OpList2[1+random() mod 2], Val1 = 2+random() mod 10, Val2 = 2+random() mod 10, F1 =.. [Op1,Val1], F2 =.. [Op2,Val2], println([f1=F1,f2=F2]), % bp.assert($(f1(X,Y) :- Y #= F1(X))), % bp.assert($(f2(X,Y) :- Y #= F2)Y)), println([op1=Op1,val1=Val1,op2=Op2,val2=Val2]), member(Len,3..20), println(len=Len), L = new_list(Len), L[1] #= StartVal, L[Len] #= EndVal, foreach(I in 2..Len) ( /* L[I] = apply(Op1,Val1,L[I-1]) ; L[I] = apply(Op2,Val2,L[I-1]) */ L[I] = apply(Op1,L[I-1],Val1) ; L[I] = apply(Op2,L[I-1],Val2) % f1(L[I-1],L[1]) % ; % f2(L[I-1],L[1]) ) end, (println(L),true ; fail), % fail, nl. go2 => true.