RosettaCodeData/Task/Dinesmans-multiple-dwelling-problem/Sidef/dinesmans-multiple-dwelling-problem-3.sidef

18 lines
536 B
Text
Raw Permalink Normal View History

2016-12-05 23:44:36 +01:00
var names = %w(Baker Cooper Fletcher Miller Smith)
2017-09-23 10:01:46 +02:00
 
2016-12-05 23:44:36 +01:00
var predicates = [
2017-09-23 10:01:46 +02:00
->(c){ :Baker != c.last },
->(c){ :Cooper != c.first },
->(c){ (:Fletcher != c.first) && (:Fletcher != c.last) },
2016-12-05 23:44:36 +01:00
->(c){ c.index(:Miller) > c.index(:Cooper) },
2017-09-23 10:01:46 +02:00
->(c){ (c.index(:Smith) - c.index(:Fletcher)).abs != 1 },
->(c){ (c.index(:Cooper) - c.index(:Fletcher)).abs != 1 },
2016-12-05 23:44:36 +01:00
]
2017-09-23 10:01:46 +02:00
 
names.permutations { |*candidate|
2016-12-05 23:44:36 +01:00
if (predicates.all {|predicate| predicate(candidate) }) {
say candidate.join("\n")
break
}
}