Name: Anonymous 2007-09-14 9:38 ID:26iR3rAD
we have a drunk person, who is standing one step away from falling from the cliff
probability of him making a step left (towards cliff) is p; right - q=1-p. He's one step away, so one step left and he dies.
for any p find the probability of him dying after n steps
This is not homework, I already did this with perl
_@_______
|
@ is personprobability of him making a step left (towards cliff) is p; right - q=1-p. He's one step away, so one step left and he dies.
for any p find the probability of him dying after n steps
This is not homework, I already did this with perl
#!/usr/bin/perl
use strict;
my $steps=eval shift or die;
sub step($$){
my($loc,$left)=@_;
return
step(($loc or return 1)-1,($left or return 0)-1)*$_+
step($loc+1,$left-1)*(1-$_);
}
printf "%.2f\t%s\n",$_,step 1,$steps foreach map{$_/100}0..100;