Skip to content

Instantly share code, notes, and snippets.

@pragmaticlogic
Created October 20, 2014 18:53
Show Gist options
  • Select an option

  • Save pragmaticlogic/3671aed051494f4eec0e to your computer and use it in GitHub Desktop.

Select an option

Save pragmaticlogic/3671aed051494f4eec0e to your computer and use it in GitHub Desktop.
Swift Tower Test Interactive
func checkTower(dest:Stack<Int>, numberOfDisks:Int) -> Bool {
var match = true
var index = 1
while match && dest.size() > 0 && index <= numberOfDisks {
match = dest.pop() == index
index++
}
return match
}
func testInteractiveTowerOfHanoi() {
let towerStacks: [Tower: Stack<Int>] = [.Tower1: Stack<Int>(), .Tower2: Stack<Int>(), .Tower3: Stack<Int>()]
let numberOfDisks = 4
for var index = numberOfDisks; index > 0; index-- {
towerStacks[.Tower1]?.push(index)
}
towerInteractive(numberOfDisks, towerStacks) //results in tower 2 as the destination
XCTAssert(checkTower(towerStacks[.Tower2]!, numberOfDisks: numberOfDisks), "Pass")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment