Skip to content

Instantly share code, notes, and snippets.

@saska-gist
Created November 24, 2018 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saska-gist/ce59c441d166aaae4a88cb56fa525b1b to your computer and use it in GitHub Desktop.
Save saska-gist/ce59c441d166aaae4a88cb56fa525b1b to your computer and use it in GitHub Desktop.
# A scip model for solving the puzzle at
# https://www.puzzleprime.com/brain-teasers/deduction/king-octopus-and-his-servants/
set s1to4 := { 1..4 };
var l[s1to4] integer >=6 <=8 ; # number of legs of each octopus (between 6 and 8)
var tl integer >=0 <= 32; # total number of legs
subto t0: sum <s> in s1to4: l[s] == tl;
var x[s1to4] binary; # is this octopus telling the truth?
subto t1:forall <s> in s1to4 do vif l[s]==6 then x[s]==1 end;
subto t2:forall <s> in s1to4 do vif l[s]==7 then x[s]==0 end;
subto t3:forall <s> in s1to4 do vif l[s]==8 then x[s]==1 end;
# what they said
subto s1: vif x[1]==1 then tl==28 else abs(tl-28)>=1 end;
subto s2: vif x[2]==1 then tl==27 else abs(tl-27)>=1 end;
subto s3: vif x[3]==1 then tl==26 else abs(tl-26)>=1 end;
subto s4: vif x[4]==1 then tl==25 else abs(tl-25)>=1 end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment