// matyconn.tc - 4/6,9-11/17 4/5,7/19 - tct // ref: http://primepuzzle.com/tunxis/matyconn.html valid int heads,total,claim [ return ((heads!=7)*(total==claim)+(heads==7)*(total!=claim)) ] main [ pl "matyconn.tc - 4/7/19 - tct" int b,r,g,y,head_count // blue,red,green,yellow // do an exhaustive search b=6 while b<=8 [ r=6 while r<=8 [ g=6 while g<=8 [ y=6 while y<=8 [ head_count=b+r+g+y // total the heads // every dragon must be a liar and give the wrong total head count or // tell the truth and give the right total head count if (valid(b,head_count,28)) [ if (valid(r,head_count,26)) [ if (valid(g,head_count,27)) [ if (valid(y,head_count,25)) [ pl "" pl "There are";pn head_count;ps " total heads." pl "" pl "The blue dragon has";pn b;ps " heads." pl "The red dragon has";pn r;ps " heads." pl "The green dragon has";pn g;ps " heads." pl "The yellow dragon has";pn y;ps " heads." pl "" ] ] ] ] y=y+1 ] g=g+1 ] r=r+1 ] b=b+1 ] pl "" ]