Skip to content

Instantly share code, notes, and snippets.

@dustinknopoff
Last active July 21, 2020 20:51
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 dustinknopoff/eff58bcf8e68417e22d124a1ea4a821b to your computer and use it in GitHub Desktop.
Save dustinknopoff/eff58bcf8e68417e22d124a1ea4a821b to your computer and use it in GitHub Desktop.
Based off of http://algorithms.wtf
fn main() {
let n = 8;
let mut blank = Vec::with_capacity(8);
hanoi(n, &mut (0..8).collect(), &mut blank.clone(), &mut blank);
}
//if n > 0
// Hanoi(n − 1, src, tmp, dst) 〈〈Recurse!〉〉
// move disk n from src to dst
// Hanoi(n − 1, tmp, dst, src) 〈〈Recurse!〉〉
fn hanoi(n: i32, src: &mut Vec<i32>, dst: &mut Vec<i32>, tmp: &mut Vec<i32>) {
if n > 0 {
hanoi(n-1,src,tmp,dst);
let nth = src.pop().unwrap();
dst.push(nth);
hanoi(n-1,tmp,dst,src);
}
dbg!((src,dst,tmp));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment