Skip to content

Instantly share code, notes, and snippets.

@austinogilvie
Last active December 17, 2015 06:29
Show Gist options
  • Select an option

  • Save austinogilvie/5565935 to your computer and use it in GitHub Desktop.

Select an option

Save austinogilvie/5565935 to your computer and use it in GitHub Desktop.
var walk = function () {
return {walk_it_out: walk_it_out}
function randint () {
var r = Math.random ()
return Math.round(r*10)
};
function get_steps (n) {
var steps = [], step;
for (var i=0; i < n; i++) {
step = Math.random () < 0.5 ? -1 : 1
steps.push(step * randint())
}
return steps;
};
function walk_it_out(n) {
var start = 100
, current = start
, steps = get_steps(n)
, positions = [start];
for (var i=0; i< steps.length; i++) {
current += steps[i]
positions.push(current)
}
return positions
}
}()
walk.walk_it_out(1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment