Skip to content

Instantly share code, notes, and snippets.

@nathwill
Created February 7, 2021 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathwill/a4cb931997026e1b8b879615eab0698c to your computer and use it in GitHub Desktop.
Save nathwill/a4cb931997026e1b8b879615eab0698c to your computer and use it in GitHub Desktop.
example random walk routine
#!/usr/bin/env ruby
#
class Rundganger
attr_accessor :coordinates, :path
def initialize
@coordinates = [0,0,0]
@path = [] << @coordinates.clone
end
def walk(steps = 3)
for _i in 1.upto(steps)
step()
@path << @coordinates.clone
end
end
def step
axis = rand(@coordinates.length)
direction = [1, -1].sample
@coordinates[axis] += direction
end
end
hans = Rundganger.new
hans.walk(10)
pp hans.path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment