function flag=runruin(s, j, p)
value=s;
while (value>0)&&(value<j)
    gamble=rand(1);
    if gamble<p  % and we assume p<1/2
        value=value+1;
    else
        value=value-1;
    end
end
if value==0
    flag=1;
else
    flag=0;
end