RosettaCodeData/Task/Dinesmans-multiple-dwelling-problem/Sidef/dinesmans-multiple-dwelling-problem-3.sidef
2017-09-25 22:28:19 +02:00

17 lines
536 B
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var names = %w(Baker Cooper Fletcher Miller Smith)
 
var predicates = [
->(c){ :Baker != c.last },
->(c){ :Cooper != c.first },
->(c){ (:Fletcher != c.first) && (:Fletcher != c.last) },
->(c){ c.index(:Miller) > c.index(:Cooper) },
->(c){ (c.index(:Smith) - c.index(:Fletcher)).abs != 1 },
->(c){ (c.index(:Cooper) - c.index(:Fletcher)).abs != 1 },
]
 
names.permutations { |*candidate|
if (predicates.all {|predicate| predicate(candidate) }) {
say candidate.join("\n")
break
}
}