/* Increasing by percentage problem (MIP approach) in Picat. Mind your decisions: "Seemingly Impossible 7th Grade Math Problem" https://mindyourdecisions.com/blog/2018/05/21/seemingly-impossible-7th-grade-math-riddle-the-coded-table/ https://www.youtube.com/watch?v=PAslxl1nIT4&feature=youtu.be """ All numbers in the first column have been incresed by the same percentage, P, to give the result in the second column. The result numbers are coded; each digit is replaced by a letter. A given letter stands for the same digit every time it appears in that column. What is the value of P, the percentage increase? 20 GC 15 IJ 45 AC 35 CG 70 JC 80 HF 25 EB 60 DG """ Compare with the CP approach: http://hakank.org/picat/increasing_by_percentage_cp.pi This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import mip. % SCIP does not handle Pct well (SCIP only support integers) main => go. go => First = [20,15,45,35,70,80,25,60], Second = [[G,C],[I,J],[A,C],[C,G],[J,C],[H,F],[E,B],[D,G]], Vars = Second.flatten().remove_dups(), Vars :: 0..9, Pct :: 1.0..2.0, foreach({FF,[AA,BB]} in zip(First,Second)) FF*Pct #= AA*10+BB end, solve($[cbc],Vars), println(pct=Pct), foreach({FF,[AA,BB]} in zip(First,Second)) printf("%d*%0.2f = %d%d\n", FF,Pct,AA,BB) end, nl.