Skip to content

Instantly share code, notes, and snippets.

@joanmolinas
Last active August 29, 2015 14:18
Show Gist options
  • Save joanmolinas/4139d06a792c7364565c to your computer and use it in GitHub Desktop.
Save joanmolinas/4139d06a792c7364565c to your computer and use it in GitHub Desktop.
prefix operator ^^ {}
prefix func ^^ (rhs : Int) -> Int {
return rhs < 0 ? 0 : rhs <= 2 ? 1 : ^^(rhs - 1) + ^^(rhs - 2)
}
postfix operator ^^ {}
postfix func ^^ (lhs : Int) -> Int {
return lhs < 0 ? 0 : lhs <= 2 ? 1 : ^^(lhs - 1) + ^^(lhs - 2)
}
infix operator ^+^ { associativity right precedence 140}
func ^+^ (lhs : Int, rhs : Int) -> Int {
return ^^rhs + ^^lhs
//USAGE
^^(-1) // OUTPUT -> 0
15^^ // OUTPUT -> 987
5^+^6 //OUTPUT -> 21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment