Last active
July 10, 2017 08:17
-
-
Save Zedd0202/51a9aee82f567a9ee38aacf6c2476fec to your computer and use it in GitHub Desktop.
iOS Missions
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
//1 | |
func distance(ax : Int, ay : Int, bx :Int, by :Int)-> Float { | |
let a = pow(Float(bx-ax), 2) | |
let b = pow(Float(by-ay), 2) | |
let sol2 : Float = a + b | |
return sol2.squareRoot() | |
} | |
print(distance(ax: 1, ay: 1, bx: 5, by: 6)) | |
//print 6.40312 | |
//2 | |
typealias Point = (a : Double, b : Double) | |
func distance2(a : Point, b : Point) -> Double { | |
let x = pow(Double(b.a-a.a), 2) | |
let y = pow(Double(b.b-a.b), 2) | |
let sol2 : Double = x + y | |
return sol2.squareRoot() | |
} | |
distance2(a: (1,1), b: (5,6)) | |
//print 6.403124237432849.. | |
//3 | |
func age(from: String ) -> Int{ | |
let index = from.index(from.startIndex, offsetBy: 4) | |
let sol = from.substring(to : index) | |
let integerYear : Int = Int(sol)! | |
let sol2 = 11707 - integerYear | |
return sol2/100 | |
} | |
print( age(from: "881201")) | |
//print 28. | |
//4 | |
let arr: [Int?] = [1,4,-1,3,2] | |
var index : Int = 0 | |
func enumerateList(A:[Int?]){ | |
while true{ | |
if arr[index] == -1{ | |
print("-1") | |
break | |
} | |
print(arr[index]!,terminator: " -> ") | |
index = arr[index]! | |
} | |
} | |
func countOfList( A: [Int?])->Int{ | |
return arr.count | |
} | |
func isFullList(A : [Int?]) -> Bool{ | |
for index in arr{ | |
if index == nil{ | |
return false | |
} | |
else { | |
return true | |
} | |
} | |
return true | |
} | |
countOfList(A: arr) | |
isFullList(A: arr) | |
enumerateList(A: arr) | |
//print 5 | |
//print true | |
//print 1 -> 4 -> 2 -> -1 | |
//5 | |
func complex(from array:[Int]) -> Int{ | |
let filtered = array.filter { index in index%2==0 || index%3==0 }.map{ $0 * 5 }.reduce(0, { $0 + $1}) | |
return filtered | |
} | |
complex(from : [1,2,3,4,5,6]) | |
//prints 75 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment