val houses = List(1, 2, 3, 4, 5)
val orderings = houses.permutations.toList
val List(first, _, middle, _, _) = houses
def imright(h1: Int, h2: Int) = h1 - h2 == 1
def nextto(h1: Int, h2: Int) = math.abs(h1 - h2) == 1
for (List(red, green, ivory, yellow, blue) <- orderings if imright(green, ivory))
for(List(englishman, spaniard, ukranian, japanese, norwegian) <- orderings
if (englishman == red)
) println(Map(
"englishman" -> englishman
,"red" -> red
,"norwegian" -> norwegian
,"first" -> first
))
1
solved Einstein’s puzzle in Scala [duplicate]