Created
September 15, 2015 06:14
-
-
Save yamamotoj/26694b9fa84febb853bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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