Skip to content

not done #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 50 additions & 5 deletions HWfrom1-09-16(SwiftIntro).playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)


*/
56 changes: 56 additions & 0 deletions HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)