20 lines
831 B
Text
20 lines
831 B
Text
var Baker, Cooper, Fletcher, Miller, Smith; // value == floor
|
|
const bottom=1,top=5; // floors: 1..5
|
|
// All live on different floors, enforced by using permutations of floors
|
|
//fcn c0{ (Baker!=Cooper!=Fletcher) and (Fletcher!=Miller!=Smith) }
|
|
fcn c1{ Baker!=top }
|
|
fcn c2{ Cooper!=bottom }
|
|
fcn c3{ bottom!=Fletcher!=top }
|
|
fcn c4{ Miller>Cooper }
|
|
fcn c5{ (Fletcher - Smith).abs() !=1 }
|
|
fcn c6{ (Fletcher - Cooper).abs()!=1 }
|
|
|
|
filters:=T(c1,c2,c3,c4,c5,c6);
|
|
dudes:=T("Baker","Cooper","Fletcher","Miller","Smith"); // for reflection
|
|
foreach combo in (Utils.Helpers.permuteW([bottom..top].walk())){ // lazy
|
|
dudes.zip(combo).apply2(fcn(nameValue){ setVar(nameValue.xplode()) });
|
|
if(not filters.runNFilter(False)){ // all constraints are True
|
|
vars.println(); // use reflection to print solution
|
|
break;
|
|
}
|
|
}
|