Skip to main content
1 of 5
Mutador
  • 1.4k
  • 10
  • 15

The Random Walker Printer

Draw a program that will write to STDOUT n times 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 mmiliseconds and the go to the next step. If the step takes the walker outsite the range 0 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.

###Example #input Mywalk(s = 0.1, n = 30)

#output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 

###Considerations

  • 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

Mutador
  • 1.4k
  • 10
  • 15