Skip to content

submit #22

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 8 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
26 changes: 26 additions & 0 deletions HWFrom1-17-16(Lists and Sorts).playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"

/*


Work on your solutions here.

Link: https://docs.google.com/document/d/1XioaEqk6VqUPA-ccQhkqP3eAoDthxYyOM9vSPB7fDkg/edit#heading=h.uopysoy45zmw

1)



2)



3)



*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions HWFrom1-17-16(Lists and Sorts).playground/timeline.xctimeline
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>
99 changes: 87 additions & 12 deletions HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,103 @@

import UIKit

var str = "Hello, playground"
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Question 1: https://www.hackerrank.com/challenges/minimum-draws

//Jim is off to a party and is searching for a matching pair of socks. His drawer is filled with socks, each pair of a different color. In its worst case scenario, how many socks (x) should Jim remove from his drawer until he finds a matching pair?

/*
func howManySocks(pairsOfSocks: Int) -> Int {

if pairsOfSocks <= 0 || pairsOfSocks == 1 {
return 0
}
let pairsOfSocksDouble = Double(pairsOfSocks)
let worstCaseSocksToRemoveDouble = ceil(pairsOfSocksDouble/2) + 1

return Int(worstCaseSocksToRemoveDouble)
}

Question 1: https://www.hackerrank.com/challenges/minimum-draws
func worstCaseScenarioDrawsFor(sockArray:[Int]) -> [Int] {
var answer = [Int]()
for pairCount in sockArray{
answer.append(howManySocks(pairCount))
}
return answer
}

Copy and paste your code:
worstCaseScenarioDrawsFor([2,3,4,5,6,7,8])

What is the big O runtime of your code?:
//What is the big O runtime of your code?:
// O(n)

Question 2: https://www.hackerrank.com/challenges/handshake

Copy and paste your code:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Question 2: https://www.hackerrank.com/challenges/handshake

What is the big O runtime of your code?:
//At the annual meeting of Board of Directors of Acme Inc, every one starts shaking hands with everyone else in the room. Given the fact that any two persons shake hand exactly once, Can you tell the total count of handshakes?

Question 3: https://www.hackerrank.com/challenges/connecting-towns
func factorial(number:Int) -> Int{
if number == 0 || number == 1 {
return 1
}
return number * factorial(number - 1)
}

Copy and paste your code:
func handshakeCountFor(boardMembers: Int) -> Int{

if (boardMembers <= 1) {
return 0
}

let r = 2
let handshakeCount = (factorial(boardMembers)) / (factorial(r) * factorial(boardMembers - r))

return handshakeCount
}

handshakeCountFor(5)

func handshakeCountsForArray(arrayOfBoardMembers: [Int]) -> [Int]{

var handShakeCounts = [Int]()
for boardMemberCount in arrayOfBoardMembers{
handShakeCounts.append(handshakeCountFor(boardMemberCount))
}
return handShakeCounts

}

handshakeCountsForArray([1,2,3,4,5,20])

//What is the big O runtime of your code?:
// O( Σ ai)

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//Question 3: https://www.hackerrank.com/challenges/connecting-towns
//Gandalf is travelling from Rohan to Rivendell to meet Frodo but there is no direct route from Rohan (T1) to Rivendell (Tn).
//But there are towns T2,T3,T4...Tn-1 such that there are N1 routes from Town T1 to T2, and in general, Ni routes from Ti to Ti+1 for i=1 to n-1 and 0 routes for any other Ti to Tj for j ≠ i+1
//Find the total number of routes Gandalf can take to reach Rivendell from Rohan.

//Note
//Gandalf has to pass all the towns Ti for i=1 to n-1 in numerical order to reach Tn.
//For each Ti , Ti+1 there are only Ni distinct routes Gandalf can take.

//Copy and paste your code:

func possibleRoutesBetweenTowns(townRoutes:[Int]) -> Int{ //number of towns is townRoutes.count + 1

var possibleRoutes = 1
for routes in townRoutes{
possibleRoutes = possibleRoutes * routes
}

return possibleRoutes
}

possibleRoutesBetweenTowns([2,3,5,6])

//What is the big O runtime of your code?:
//O(n)

What is the big O runtime of your code?:

*/