/* Enigma 441: The coloured painting in Picat. https://enigmaticcode.wordpress.com/2018/03/23/enigma-441-the-coloured-painting/ """ From New Scientist #1591, 17th December 1987 [link] I looked down at the body slumped over my desk. One hand held my card “Newton Harlowe — Private detective”, and the other a painting. All I knew about painting came from watching my secretary Velda doing her nails. However, I could see in the dim light that is was a 6 × 6 array of small squares, each coloured red or blue or green. As the neon lights on the nightclubs opposite my office window flashed on and off and the light reflected from the wet sidewalks, I was able to make out the vertical columns of the painting. I saw: [ RBGGBR BBGRRG GGRBRB RGBRBG GRRBGB BRBGGR ] though that was not necessarily the order they occurred in the painting. Suddenly the door opened and a raincoated figure with an automatic entered. There was a loud bang and everything went black. I came round to find myself lying next to the body of a blonde on the floor of a living room. From the sound of the surf outside I could tell it was a beach-house. There on the wall was the painting. The moonlight shone onto it through the shutters. As they moved in the breeze I was able to make out the horizontal rows of the painting. I saw: [ BGBRGR RBBGRG GGRBRB RRGBGB GBRRBG BRGGBR ] though again not necessarily in the right order. Just then a police siren sounded outside. I was going to have to do some explaining, and that painting was the key. Reproduce the painting. """ Solution (the painting): RBBGRG GBRRBG BGBRGR RRGBGB BRGGBR GGRBRB This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 6, Colors = [R,G,B], Colors = 1..3, ColorsS = ['R','G','B'], % rows, in some order Rows = [ [B,G,B,R,G,R], [R,B,B,G,R,G], [G,G,R,B,R,B], [R,R,G,B,G,B], [G,B,R,R,B,G], [B,R,G,G,B,R]], % columns, in some order Cols = [ [R,B,G,G,B,R], [B,B,G,R,R,G], [G,G,R,B,R,B], [R,G,B,R,B,G], [G,R,R,B,G,B], [B,R,B,G,G,R]], % decision variables RowsOrder = new_list(N), RowsOrder :: 1..N, ColsOrder = new_list(N), ColsOrder :: 1..N, all_different(RowsOrder), all_different(ColsOrder), foreach(I in 1..N, J in 1..N) % Rows[RowsOrder[I],J] #= Cols[ColsOrder[J],I] matrix_element(Rows,RowsOrder[I],J,T), matrix_element(Cols,ColsOrder[J],I,T) end, Vars = RowsOrder.vars ++ ColsOrder.vars, solve(Vars), println(rowsOrder=RowsOrder), println(colsOrder=ColsOrder), nl, println("The painting:"), foreach(I in RowsOrder) println([ColorsS[Rows[I,J]] : J in 1..N]) end, nl, fail, nl. go => true.