Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Amb/Scala/amb.scala
Normal file
20
Task/Amb/Scala/amb.scala
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
object Amb {
|
||||
|
||||
def amb(wss: List[List[String]]): Option[String] = {
|
||||
def _amb(ws: List[String], wss: List[List[String]]): Option[String] = wss match {
|
||||
case Nil => ((Some(ws.head): Option[String]) /: ws.tail)((a, w) => a match {
|
||||
case Some(x) => if (x.last == w.head) Some(x + " " + w) else None
|
||||
case None => None
|
||||
})
|
||||
case ws1 :: wss1 => ws1.flatMap(w => _amb(w :: ws, wss1)).headOption
|
||||
}
|
||||
_amb(Nil, wss.reverse)
|
||||
}
|
||||
|
||||
def main(args: Array[String]) {
|
||||
println(amb(List(List("the", "that", "a"),
|
||||
List("frog", "elephant", "thing"),
|
||||
List("walked", "treaded", "grows"),
|
||||
List("slowly", "quickly"))))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue