# coding: utf-8
require 'minitest/autorun'
P=
->l,m,x,y{!((r=0...l)===x&&r===y)?0:m<1?1:(0..7).map{|i|a,b=[1,2].rotate i[2]
P[l,m-1,x+a*(i[0]*2-1),y+b*(i[1]*2-1)]/8.0}.inject(:+)}
describe P do
def test_0_moves
assert_equal 1, P[5, 0, 2, 2]
end
def test_1_move
assert_equal 1, P[5, 1, 2, 2]
end
def test_2_moves
assert_equal 0.375, P[5, 2, 2, 2]
end
def test_3_moves
assert_equal 0.25, P[5, 3, 2, 2]
end
def test_4_moves
assert_equal 0.1171875, P[5, 4, 2, 2]
end
def test_5_moves
assert_equal 0.06640625, P[5, 5, 2, 2]
end
end
IyBjb2Rpbmc6IHV0Zi04CnJlcXVpcmUgJ21pbml0ZXN0L2F1dG9ydW4nCgpQPQotPmwsbSx4LHl7ISgocj0wLi4ubCk9PT14JiZyPT09eSk/MDptPDE/MTooMC4uNykubWFwe3xpfGEsYj1bMSwyXS5yb3RhdGUgaVsyXQpQW2wsbS0xLHgrYSooaVswXSoyLTEpLHkrYiooaVsxXSoyLTEpXS84LjB9LmluamVjdCg6Kyl9CgpkZXNjcmliZSBQIGRvCiAgZGVmIHRlc3RfMF9tb3ZlcwogICAgYXNzZXJ0X2VxdWFsIDEsIFBbNSwgMCwgMiwgMl0KICBlbmQKCiAgZGVmIHRlc3RfMV9tb3ZlCiAgICBhc3NlcnRfZXF1YWwgMSwgUFs1LCAxLCAyLCAyXQogIGVuZAoKICBkZWYgdGVzdF8yX21vdmVzCiAgICBhc3NlcnRfZXF1YWwgMC4zNzUsIFBbNSwgMiwgMiwgMl0KICBlbmQKCiAgZGVmIHRlc3RfM19tb3ZlcwogICAgYXNzZXJ0X2VxdWFsIDAuMjUsIFBbNSwgMywgMiwgMl0KICBlbmQKCiAgZGVmIHRlc3RfNF9tb3ZlcwogICAgYXNzZXJ0X2VxdWFsIDAuMTE3MTg3NSwgUFs1LCA0LCAyLCAyXQogIGVuZAoKICBkZWYgdGVzdF81X21vdmVzCiAgICBhc3NlcnRfZXF1YWwgMC4wNjY0MDYyNSwgUFs1LCA1LCAyLCAyXQogIGVuZAplbmQK