fork(1) download
  1. # coding: utf-8
  2. require 'minitest/autorun'
  3.  
  4. P=
  5. ->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]
  6. P[l,m-1,x+a*(i[0]*2-1),y+b*(i[1]*2-1)]/8.0}.inject(:+)}
  7.  
  8. describe P do
  9. def test_0_moves
  10. assert_equal 1, P[5, 0, 2, 2]
  11. end
  12.  
  13. def test_1_move
  14. assert_equal 1, P[5, 1, 2, 2]
  15. end
  16.  
  17. def test_2_moves
  18. assert_equal 0.375, P[5, 2, 2, 2]
  19. end
  20.  
  21. def test_3_moves
  22. assert_equal 0.25, P[5, 3, 2, 2]
  23. end
  24.  
  25. def test_4_moves
  26. assert_equal 0.1171875, P[5, 4, 2, 2]
  27. end
  28.  
  29. def test_5_moves
  30. assert_equal 0.06640625, P[5, 5, 2, 2]
  31. end
  32. end
  33.  
Success #stdin #stdout 0.08s 8536KB
stdin
Standard input is empty
stdout
Run options: --seed 42825

# Running tests:

......

Finished tests in 0.022986s, 261.0325 tests/s, 261.0325 assertions/s.

6 tests, 6 assertions, 0 failures, 0 errors, 0 skips