Skip to content

Instantly share code, notes, and snippets.

@Cartman0
Created June 9, 2015 07:00
Show Gist options
  • Save Cartman0/61ec893d974400ec5530 to your computer and use it in GitHub Desktop.
Save Cartman0/61ec893d974400ec5530 to your computer and use it in GitHub Desktop.
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