Draw a program or function that will write to
n times (each for one step) a string that contains a dot
. at the location of the walker. The program also needs to write a line every
s seconds (or wait
s seconds after each line).
A random walk is a mathematical formalization of a path that consists of a succession of random steps (wiki), such that every new step will be the last step plus a new value, so any
tstep value is just the sum of all the random values before ir plus the initial value.
The program should take 2 inputs and will use only spaces
" " and dots
"." on the output. The start value of the walker will be
20 such that the output should be a dot after 19 spaces.
. #19 spaces then a dot
Every new step the value will be the last value of the walker plus one of these
[-2-1,0,1,2](20% chance each). After the new position is printed the program should wait
s seconds and the go to the next step. If the step takes the walker outsite the range
1 to 40 it should be just ignored and the walker position stays the same. The number of spaces will always be a number from 0 to 39.
#input Mywalk(s = 0.1, n = 30) #output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
You may take the input as any reasonable format
The shortest code wins
It's okay if your program only accept the seconds as integers