Last active
July 21, 2020 20:51
-
-
Save dustinknopoff/eff58bcf8e68417e22d124a1ea4a821b to your computer and use it in GitHub Desktop.
Based off of http://algorithms.wtf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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