Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Project Euler #1 Solution in Swift
// 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
You can’t perform that action at this time.