Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Last active December 30, 2015 17:59
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 robotlolita/7864258 to your computer and use it in GitHub Desktop.
Save robotlolita/7864258 to your computer and use it in GitHub Desktop.
function find_paths(w, h, downs, rights, path, paths, continuation) {
if ((downs == h) && (rights == w)) {
draw_path(path)
setTimeout(function() {
continuation(paths + 1)
}, 1000)
}
else if (downs < h) {
find_paths(w, h, downs + 1, rights, path.concat('d'), paths, continuation)
}
else if (rights < w) {
find_paths(w, h, downs, rights + 1, path.concat('r'), paths, continuation)
}
else {
continuation(paths)
}
}
function find_paths(w, h, downs, rights, path, paths) {
if ((downs == h) && (rights == w)) {
draw_path(path);
// I want the equivalent of sleep(1) here
return paths + 1;
}
if (downs < h)
paths = find_paths(w, h, downs+1, rights, path.concat('d'), paths);
if (rights < w)
paths = find_paths(w, h, downs, rights+1, path.concat('r'), paths);
return paths
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment