Skip to content

Instantly share code, notes, and snippets.

@yamamotoj
Created September 15, 2015 06:14
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 yamamotoj/26694b9fa84febb853bc to your computer and use it in GitHub Desktop.
Save yamamotoj/26694b9fa84febb853bc to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
class Pole{
let left:Int
let right: Int
init(_ left:Int, _ right:Int){
self.left = left
self.right = right
}
func landLeft(birds:Int) -> Pole?{
if(abs(birds + left - right) < 4){
return Pole((left + birds), right)
}
return nil
}
func landRight(birds:Int) -> Pole?{
if(abs(left - (right + birds)) < 4){
return Pole(left, right + birds)
}
return nil
}
func banana() -> Pole?{
return nil
}
}
let p1 = Pole(0, 0).landLeft(3)?.landLeft(1)
let p2 = Pole(0, 0).landLeft(3)?.landRight(2)
func return_<T> (p:T) -> T?{
return Optional.Some(p)
}
func do_() -> Pole?{
if let
start = return_(Pole(0, 0)),
first = start.landLeft(2),
second = first.landLeft(1),
last = second.landRight(2)
{
return return_(last)
}
return Optional.None
}
let p = do_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment