Skip to content

Instantly share code, notes, and snippets.

@cennydavidsson
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save cennydavidsson/056aca15d49bb7ad1ea6 to your computer and use it in GitHub Desktop.

Select an option

Save cennydavidsson/056aca15d49bb7ad1ea6 to your computer and use it in GitHub Desktop.
First attempt to rewrite some of the Solution codebase to swift.
func validInput(input:String) -> Bool {
var last = ""
if let x = equation.last { last = x }
switch last {
case "+", "-", "*", "(", "":
switch input {
case let x where input.toInt() != nil:
return true
case "(":
return true
default:
return false
}
case let x where last.toInt() != nil:
switch input {
case "+", "-", "*", ")" where parenthesesStack > 0:
return true
default:
return false
}
case ")":
switch input {
case "+", "-", "*", "(", ")":
return true
default:
return false
}
default:
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment