Skip to content

Instantly share code, notes, and snippets.

@s00d
Created January 20, 2017 18:41
Show Gist options
  • Save s00d/f19e36cfb66ddd6fd535ed9a95acf3bd to your computer and use it in GitHub Desktop.
Save s00d/f19e36cfb66ddd6fd535ed9a95acf3bd to your computer and use it in GitHub Desktop.
class honoiClass {
isValidMove(sIdx, eIdx, startSelect, endSelect) {
if(startSelect > this.state.numDisks - 1 || endSelect < 0) return false;
if (this.state.stacks[sIdx][startSelect] === 0) {
return this.isValidMove(sIdx, eIdx, startSelect + 1, endSelect);
} else if (this.state.stacks[eIdx][endSelect] !== 0) {
if (this.state.stacks[sIdx][startSelect] < this.state.stacks[eIdx][endSelect]) {
return this.isValidMove(sIdx, eIdx, startSelect, endSelect-1);
} else {
return false;
}
} else return {start: startSelect, end: endSelect};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment