diff --git a/HWfrom1-09-16(SwiftIntro).playground/Contents.swift b/HWfrom1-09-16(SwiftIntro).playground/Contents.swift index 488e9ed..03c7f66 100644 --- a/HWfrom1-09-16(SwiftIntro).playground/Contents.swift +++ b/HWfrom1-09-16(SwiftIntro).playground/Contents.swift @@ -11,13 +11,58 @@ Use the link here to get the questions. Then code your solutions below. If it https://docs.google.com/document/d/1DQ2aCJ_yUZtazzCfb0PaS81bg61V2ZOSxpABh981xSo/edit -1) +1) Not sure what you're asking. + +*/ + +//2) + var numbers = [1,2,2,4,6,54,7,9,1,4] + var numbers2 = [5, 3, 8, 11] + +func duplicateElements(arr1: [Int]) -> Bool { + + let arr2 = Array(Set(arr1)) + + if arr2.count < arr1.count { + return true + } else { + return false + } +} + +duplicateElements(numbers) +duplicateElements(numbers2) + +//3) + + + +var list1 = [1,2,5,9] +var list2 = [9, 20 , 5] + +list1.sort() +let smallestVal = list1[0] + +list2.sort() +let list2SmallestVal = list2[0] + + + +//4) + + + + + + + + + + + + -2) -3) -4) -*/ diff --git a/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift b/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift index bc0df91..b62c48d 100644 --- a/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift +++ b/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift @@ -27,3 +27,59 @@ What is the big O runtime of your code?: */ +//1. The number of draws he makes in the worst case scenario is 3. I don't know how to express that in code. + +//2. + + +func factorial(var value: Int, var result: Int = 1) -> Int { + + if (value == 0) { + return result + } + + result *= value + value-- + + return factorial(value, result: result) + } + +func handshakes(attendees: Int) -> Int { + + let num = factorial(attendees) + + let den = (factorial(2) * factorial(attendees - 2)) + + let total = num / den + + return total + +} + + +handshakes(4) +handshakes(2) + +//3. +func gandalfsRoute(routes: Int, towns: Int) ->Int { + let num = factorial(routes) + let den = factorial(routes - towns) + + let total = num / den + + return total + +} + +gandalfsRoute(2, towns: 2) +gandalfsRoute(3, towns: 2) + + + + + + + + + +