f=
->s{Z=(s.split'
')<<[]
K=[]
F=->i,j,f{k=Z[i][j]
K[i]||=0
k==?^?2.times{|m|F[i+1,j+m,f/2]}:!k ?K[j]+=f :F[i+1,j+(k==?/?0:1),f]}
F[0,0,1.0]
K}
test=[
"",
"^",
"/",
"\\",
"/
^^",
"^
^^
^^^",
"\\
/\\
//\\",
"^
\\^
^^\\
\\^/^",
"^
/^
^^/
/\\/\\
^^/^\\
^\\^\\/^
\\^^^\\^/"
]
test.map{|x|[x,f[x]]}.each{|x|puts x[0];p x[1];puts''}
Zj0KLT5ze1o9KHMuc3BsaXQnCicpPDxbXQpLPVtdCkY9LT5pLGosZntrPVpbaV1bal0KS1tpXXx8PTAKaz09P14/Mi50aW1lc3t8bXxGW2krMSxqK20sZi8yXX06IWsgP0tbal0rPWYgOkZbaSsxLGorKGs9PT8vPzA6MSksZl19CkZbMCwwLDEuMF0KS30KCgp0ZXN0PVsKIiIsCiJeIiwKIi8iLAoiXFwiLAoiLwpeXiIsCiJeCl5eCl5eXiIsCiJcXAovXFwKLy9cXCIsCiJeClxcXgpeXlxcClxcXi9eIiwKIl4KL14KXl4vCi9cXC9cXApeXi9eXFwKXlxcXlxcL14KXFxeXl5cXF4vIgpdCgp0ZXN0Lm1hcHt8eHxbeCxmW3hdXX0uZWFjaHt8eHxwdXRzIHhbMF07cCB4WzFdO3B1dHMnJ30=
[1.0]
^
[0.5, 0.5]
/
[1.0, 0]
\
[0, 1.0]
/
^^
[0.5, 0.5, 0]
^
^^
^^^
[0.125, 0.375, 0.375, 0.125]
\
/\
//\
[0, 0, 0, 1.0]
^
\^
^^\
\^/^
[0, 0.1875, 0.5625, 0.125, 0.125]
^
/^
^^/
/\/\
^^/^\
^\^\/^
\^^^\^/
[0, 0.09375, 0.28125, 0.4375, 0.1875, 0, 0, 0]
prog.rb:2: warning: already initialized constant Z
prog.rb:4: warning: already initialized constant K
prog.rb:5: warning: already initialized constant F
prog.rb:2: warning: already initialized constant Z
prog.rb:4: warning: already initialized constant K
prog.rb:5: warning: already initialized constant F
prog.rb:2: warning: already initialized constant Z
prog.rb:4: warning: already initialized constant K
prog.rb:5: warning: already initialized constant F
prog.rb:2: warning: already initialized constant Z
prog.rb:4: warning: already initialized constant K
prog.rb:5: warning: already initialized constant F
prog.rb:2: warning: already initialized constant Z
prog.rb:4: warning: already initialized constant K
prog.rb:5: warning: already initialized constant F
prog.rb:2: warning: already initialized constant Z
prog.rb:4: warning: already initialized constant K
prog.rb:5: warning: already initialized constant F
prog.rb:2: warning: already initialized constant Z
prog.rb:4: warning: already initialized constant K
prog.rb:5: warning: already initialized constant F
prog.rb:2: warning: already initialized constant Z
prog.rb:4: warning: already initialized constant K
prog.rb:5: warning: already initialized constant F