Created
June 9, 2015 07:00
-
-
Save Cartman0/61ec893d974400ec5530 to your computer and use it in GitHub Desktop.
Project Euler #1 Solution in Swift
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
// Project Euler #1 Solution in Swift | |
/*Project Eulerの1問目 | |
http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%201 | |
*/ | |
func anyMultipleOf(value: Int, numbers: [Int]) -> Bool { | |
return numbers.reduce(false) { | |
any, number in | |
print("any") | |
print(" : ") | |
print(any) | |
print(" ") | |
print(value) | |
print(" % ") | |
print(number) | |
print(" : ") | |
print(((value % number) == 0)) | |
print(" ") | |
println(any || ((value % number) == 0)) | |
return any || ((value % number) == 0) | |
} | |
} | |
let sum = [Int](1..<10).filter() { anyMultipleOf($0, [3, 5]) }.reduce(0) { | |
print($0) | |
print(" ") | |
println($1) | |
return $0 + $1 | |
} | |
println(sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment