Created
September 24, 2015 11:01
-
-
Save motokiee/a8d8865b7d60ef096dd6 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
func chain(num:Int) -> [Int] { | |
guard num > 0 else { | |
fatalError("can not calculate with 0") | |
} | |
switch num { | |
case 1: | |
return [1] | |
case let num where num % 2 == 0: | |
return [num] + chain(num/2) | |
default: | |
return [num] + chain(num*3+1) | |
} | |
} | |
(1...100).map { (num:Int) -> [Int] in | |
return chain(num) | |
}.filter { (nums:[Int]) -> Bool in | |
nums.count > 15 | |
}.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment