# [Scala][1], <del>378</del> 336 bytes Port of [@bsoelch's Python answer][2] in Scala. Saved 42 bytes thanks to the comment of [@Kjetil S][3] --- Golfed version. [Try it online!][4] ```scala def f(s:(Int,Int),b:Seq[(Int,Int)],t:(Int,Int),K:Int=0)={var p=Seq(s);var k=K;while(!p.contains(t)&&k<64){p=(for(i<-0 until 64;u=i/8;v=i%8;if !b.contains((u,v))&&p.exists{case(x,y)=>(x-u)*(x-u)+(y-v)*(y-v)==5})yield(u,v)).toList;k+=1};k%64} def C(s:String)=(s(0)-97,s(1)-49) def h(a:String,b:List[String],c:String)=f(C(a),b.map(C),C(c)) ``` Ungolfed version. [Try it online!][5] ```scala object Main { def f(s: (Int, Int), b: List[(Int, Int)], t: (Int, Int), k: Int = 0): Int = { var p = List(s) var kVar = k while (!p.contains(t) && kVar < 64) { p = (for (i <- 0 until 64; u = i / 8; v = i % 8; if !b.contains((u, v)) && p.exists { case (x, y) => (x - u) * (x - u) + (y - v) * (y - v) == 5 }) yield (u, v)).toList kVar += 1 } kVar % 64 } def coord(s: String): (Int, Int) = { ("abcdefgh".indexOf(s.charAt(0)), s.charAt(1).asDigit - 1) } def helper(a: String, b: List[String], c: String): Int = { f(coord(a), b.map(coord), coord(c)) } def main(args: Array[String]): Unit = { println(helper("e3", List(), "f5")) //-> 1 println(helper("e3", List(), "f6")) //-> 2 println(helper("c4", List(), "f6")) //-> 3 println(helper("g1", List("f3", "g3"), "h4")) //-> 4 println(helper("c4", List("d6", "b6", "e5", "e3", "e4"), "f6")) //-> 5 println(helper("a1", List(), "h8")) //-> 6 println(helper("g1", List("h3","h5","g2","g3","g6","f3", "e5", "e6", "d4", "d5", "c1", "c3", "c5", "b2"), "b7")) //-> 7 println(helper("h1", List("f2", "g3"), "h3")) //-> 0 println(helper("d4", List("b3", "b5", "c2", "c6", "e2", "e6", "f3", "f5"), "a8")) //-> 0 } } ``` [1]: http://www.scala-lang.org/ [2]: https://codegolf.stackexchange.com/a/264739/110802 [3]: https://codegolf.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