//มี 5 ชนชาติ
var sol = from n in ArrayExt.Enum<Nationality>().ToConstraintList(5)
//5 สีบ้าน
from c in ArrayExt.Enum<HouseColor>().ToConstraintList(5)
//5 บุหรี่
from s in ArrayExt.Enum<Smoke>().ToConstraintList(5)
//5 เครื่องดื่ม
from d in ArrayExt.Enum<Drink>().ToConstraintList(5)
//5 สัตว์เลี้ยง
from p in ArrayExt.Enum<Pet>().ToConstraintList(5)
//i จะเป็นเลขใดก็ได้ 0-4
from i in 0.To(4).ToConstraintIndex()
//ไม่มีชนชาติเดียวกัน
where Constraint.AllDifferent(n)
//ไม่มีสีบ้านเดียวกัน
where Constraint.AllDifferent(c)
//ไม่มีบุหรี่ยี่ห้อเดียวกัน
where Constraint.AllDifferent(s)
//ไม่มีเครื่องดื่มเดียวกัน
where Constraint.AllDifferent(d)
//ไม่มีสัตว์เลี้ยงเดียวกัน
where Constraint.AllDifferent(p)
//คนที่เป็นชาวอังกฤษอยู่บ้านสีแดง
where (n[i] == Nationality.British) == (c[i] == HouseColor.Red)
//คนที่เป็นชาวสวีเดนเลี้ยงหมา
where (n[i] == Nationality.Swedish) == (p[i] == Pet.Dog)
//คนที่เป็นชาวเดนมาร์กดื่มชา
where (n[i] == Nationality.Danish) == (d[i] == Drink.Tea)
//บ้านสีเขียวอยู่ทางซ้ายของบ้านสีขาว
where (c[i] == HouseColor.Green) == (c[i + 1] == HouseColor.White)
//เจ้าของบ้านสีเขียวดื่มกาแฟ
where (c[i] == HouseColor.Green) == (d[i] == Drink.Coffee)
//คนที่สูบบุหรี่ยี่ห้อ Pall Mall เป็นคนเลี้ยงนก
where (s[i] == Smoke.PallMall) == (p[i] == Pet.Bird)
//เจ้าของบ้านสีเหลืองสูบบุหรี่ยี่ห้อ Dunhill
where (c[i] == HouseColor.Yellow) == (s[i] == Smoke.DunHill)
//คนที่อยู่บ้านหลังกลางดื่มนม
where d[2] == Drink.Milk
//คนที่เป็นชาวนอร์เวย์อยู่บ้านหลังแรก
where n[0] == Nationality.Norwegian
//คนที่สูบบุหรี่ยี่ห้อ Blends เป็นเพื่อนบ้านกับคนที่ดื่มน้ำ
where ((s[i] == Smoke.Blend) ?
(d[i - 1] == Drink.Water || d[i + 1] == Drink.Water) : true)
//คนที่เลี้ยงม้าอยู่ติดกับคนที่สูบบุหรี่ยี่ห้อ Dunhill
where ((p[i] == Pet.Horse) ?
(s[i - 1] == Smoke.DunHill || s[i + 1] == Smoke.DunHill) : true)
//คนที่สูบบุหรี่ยี่ห้อ Bulemaster ดื่มเบียร์
where (s[i] == Smoke.BlueMaster) == (d[i] == Drink.Beer)
//คนที่เป็นชาวเยอรมันสูบบุหรี่ยี่ห้อ Prince
where (n[i] == Nationality.German) == (s[i] == Smoke.Prince)
//คนที่เป็นชาวนอร์เวย์อยู่ติดกับบ้านสีฟ้า
where ((n[i] == Nationality.Norwegian) ?
(c[i - 1] == HouseColor.Blue || c[i + 1] == HouseColor.Blue) : true)
//คนที่สูบบุหรี่ยี่ห้อ Blends อยู่ติดกับคนเลี้ยงแมว
where (p[i] == Pet.Cat) ?
(s[i - 1] == Smoke.Blend || s[i + 1] == Smoke.Blend) : true
select 0.To(4).Select(x =>
new {
Nationality = n[x],
HouseColor = c[x],
Smoke = s[x],
Drink = d[x],
Pet = p[x]
});