Skip to content

Instantly share code, notes, and snippets.

@nathwill
Created February 7, 2021 07:31
Show Gist options
  • 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