文字列の八方向検索
Posted feedbacks - Scala
ふつうに。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | object esearch {
val ds = List(("", 0), ("Left", -1), ("Right", 1)).map{h=>
List(("", 0), ("Upper", -1), ("Lower", 1)).map{(h, _)}}
.foldLeft(List[((String,Int),(String,Int))]()){_:::_}.tail
def apply(s:String, s1:String) = {
val smap = s.split("\n")
smap.zipWithIndex.foreach{case (l, y) =>
l.toArray.zipWithIndex.foreach{case (c, x) =>
if(c==s1(0)){
ds.foreach{ d=>
if((1 until s1.size).forall{ i=>
try{
smap(y+i*d._2._2)(x+i*d._1._2) == s1(i)
}catch{ case e => false }
}) println("("+x+","+y+"), "+d._1._1+d._2._1)
}
}
}
}
}
}
|



kuromin #4400() Rating0/2=0.00
[ reply ]