Zebra puzzle in Scala

后端 未结 1 1873
没有蜡笔的小新
没有蜡笔的小新 2021-01-23 00:47

I\'m trying to work through Udacity\'s CS212 using Scala but had trouble with the Zebra Puzzle,

Some of the concepts in python just doesn\'t convert to Scala easily, esp

相关标签:
1条回答
  • 2021-01-23 01:37

    You want

    val houses = List(1, 2, 3, 4, 5)
    val List(first, _, middle, _, _) = houses
    

    and

    for (List(red, green, ivory, yellow, blue) <- orderings)
    

    respectively. Also, note that in Scala these sorts of destructurings must be assigned to variables starting with a lower-case letter; upper-case indicates that it is instead supposed to match an existing variable (or throw an exception if it does not!).

    0 讨论(0)
提交回复
热议问题