Skip to content

Instantly share code, notes, and snippets.

@stoiandan
Created April 30, 2020 18:34
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 stoiandan/1c68197e564c01932496155c7962c0f3 to your computer and use it in GitHub Desktop.
Save stoiandan/1c68197e564c01932496155c7962c0f3 to your computer and use it in GitHub Desktop.
import Foundation
class Rod {
fileprivate var stack = [Int]()
public func stackOnTop(diskSize newDiskSize: Int) throws {
if let topDiskSize = stack.popLast() {
guard topDiskSize > newDiskSize else {
throw RodSizeError.RodSizeIsTooHigh(topDiskSize: topDiskSize, diskToBeInsertedSize: newDiskSize)
}
}
stack.append(newDiskSize)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment