Let us consider a one-dimensional walk, whose steps are +1 and -1.
The probability to move forward or backward is 50% (in other words p = 1/2)
I would like to code a function step(N) that tells us the position of "L" after N-steps.
My approach:
N = 10
for i in 1:N
if randn() > 0
i = +1
print(1)
else
i = -1
print(-1)
end
end
I get results like: 11-1-11-1-1 etc. In other words these are the steps that our point L takes for N steps. However, I am not sure how to take the sum of all these steps, so that I know where L is. (I am also not sure how to save it as a function).
