From d0728b84cd956d5f504861b4e9878c7bf3a8fb4e Mon Sep 17 00:00:00 2001 From: jmeggesto Date: Thu, 14 Jan 2016 15:24:53 -0500 Subject: [PATCH 1/5] finishing up other algorithms --- .DS_Store | Bin 0 -> 6148 bytes .../Contents.swift | 64 +++++++- .../Contents.swift | 141 ++++++++++++++++-- binarysearch.swift | 29 ++++ 4 files changed, 215 insertions(+), 19 deletions(-) create mode 100644 .DS_Store create mode 100644 binarysearch.swift diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..12a572ed6dc933c98f5fab447635662b078eb08c GIT binary patch literal 6148 zcmeH~y-EW?6ot=dil9xfvJuxp)FNUOB6dq$i8flKu#L%L6tZsA1hJ8Q3g5#rh3_D~ zfe&Go#&c%|*|1TB#2_*k?me5Cx%2a}JCgyRD!s4-6aeJuqPaPS5hnHG8Jn>slBaYZ zF(Q;u#1{54tzCg5;0XLR0`l#y;t;1e#|_foZ;@Ye8SALw4wtO$;s{ra(rN<_*hB|y zoZ%iVUDji5*lv|-%{c0qWiAaS+j|rTLD=gyf!F@af*xanbC2Ti7klqqq{-A}^2-_S zCGMQEdm8c;a&O^;w12>Q?Q#4bQ+%JF_GOCW&T+)5x5ryGS=^#QO1q3Zd@sxNhAs(7 z?if{EqdNQ^uDo+4QyDi!us?Xy1gA3Y2+n%&Zv)S4vHZMI7aajdz!CT)Ap3(y7xk?s zM)lUgpsxVb9E-K_S?&^&<5~5sCPrC9Qzn&aQkA`8D3i`|&$jceCPqyDj z6s1RJ|DJ9RC3CxMZALJ-rq-$fHCl6HLYGRZnH1|h9V{pL{m@0t}tDn4m literal 0 HcmV?d00001 diff --git a/HWfrom1-09-16(SwiftIntro).playground/Contents.swift b/HWfrom1-09-16(SwiftIntro).playground/Contents.swift index 488e9ed..dc89ddc 100644 --- a/HWfrom1-09-16(SwiftIntro).playground/Contents.swift +++ b/HWfrom1-09-16(SwiftIntro).playground/Contents.swift @@ -4,20 +4,68 @@ import UIKit var str = "Hello, playground" -/* -Use the link here to get the questions. Then code your solutions below. If it does not require code, just write your answer in comments. -https://docs.google.com/document/d/1DQ2aCJ_yUZtazzCfb0PaS81bg61V2ZOSxpABh981xSo/edit +// Use the link here to get the questions. Then code your solutions below. If it does not require code, just write your answer in comments. +// https://docs.google.com/document/d/1DQ2aCJ_yUZtazzCfb0PaS81bg61V2ZOSxpABh981xSo/edit -1) -2) +// 1) -3) +func integer_algorithm(numbers: [Int]) -> Int { + + let complete: Set = Set(Range(start: 1, end: numbers.count + 1)) + let incomplete = Set(numbers) + + return Array(complete.subtract(incomplete))[0] + + +} -4) -*/ + +// 2) + +func contains_duplicates_easyway(list: [Int]) -> Bool { + + + return list.count > Set(list).count + +} + + + +// 3) + +func smallest_value(list:[Int], other_list: [Int]) -> Int? { + + return Set(list).intersect(Set(other_list)).minElement() + + + +} + + +// 4) + +func number_is_palindrome(number: Int) -> Bool { + + var array = Array() + var reversearray = Array() + var numcopy = number + + while numcopy > 0 { + + array.append(numcopy % 10) + reversearray.insert(numcopy % 10, atIndex: 0) + numcopy = numcopy / 10 + + } + + return array == reversearray + +} + + diff --git a/HWfrom1-10-016(BigO).playground/Contents.swift b/HWfrom1-10-016(BigO).playground/Contents.swift index 2040d38..09e00a3 100644 --- a/HWfrom1-10-016(BigO).playground/Contents.swift +++ b/HWfrom1-10-016(BigO).playground/Contents.swift @@ -4,27 +4,146 @@ import UIKit var str = "Hello, playground" -/* -Use the link here to get the questions. Then code your solutions below. If it does not require code, just write your answer in comments. -https://docs.google.com/document/d/1aF1imJUVahCSJAuN1OEm5lQXwpSFaAmVmAETKMM6PLQ/edit#heading=h.za36ai6n5fth +// Use the link here to get the questions. Then code your solutions below. If it does not require code, just write your answer in comments. +// https://docs.google.com/document/d/1aF1imJUVahCSJAuN1OEm5lQXwpSFaAmVmAETKMM6PLQ/edit#heading=h.za36ai6n5fth -1) -2) +// 1) +func AwesomeFilter(array: [Int], width: Int, height: Int) -> Int { + + var time = 10 //init i, store in memory + + for (var i = 0; i < width; i++) { + + time += 10 // init j each iteration of loop, store in memory + time += 3 // math operation i < width + time += 1 // access memory of i + time += 10 // write to memory + time += 3 //math operation + + for (var j = 0; j < height; j++) { + + time += 3 // math operation i < width + time += 1 // access memory of i + time += 10 // write to memory + time += 3 //math operation + time += 201 // 200 picosecond function, plus 1 psecond of memory access + } + + } + + + return time + +} +let answer = 436027010 // time in picoseconds + +let time_complexity_answer1 = "O(nm)" +let time_complexity_answer2 = "O(nm(n^2))" -3) -4) -5) +//2) -6) +//2a) O(n^2) -7) +//2b) + +func frobnicate(ys: [Int], m: Int) -> Int { + + if m == 0 { + + return 0 + } + return ys[m] + frobnicate(ys, m: m - 1) + + + +} + +//O(log(n)) + +//2c) O(n^2) + + + + +//3) + +//4) + + +func factorial(number: Int) -> Int { + + var product = 1 + for num in 1...number { + + product *= num + + } + + return product +} + +//complexity: O(n) + +//5) + +func multip(number: Int, byNumber: Int) -> Int { + + + var sum = 0 + for _ in 1...byNumber { + + sum += number + + + } + + return sum + + +} + + + +//Complexity: Wholly determined by byNumber. Linear time. + +//6) + +func peasant_mult(var number: Int, var byNumber: Int) -> Int { + + + + var sum = 0 + while byNumber != 0 { + + + if byNumber % 2 != 0 { + + sum += number + + } + + number *= 2 + byNumber = byNumber / 2 + + + } + //compexity: O(log(n)) + return sum +} + +peasant_mult(10, byNumber: 10) + + +//time complexity: + + +//7) -*/ diff --git a/binarysearch.swift b/binarysearch.swift new file mode 100644 index 0000000..e5e132f --- /dev/null +++ b/binarysearch.swift @@ -0,0 +1,29 @@ +func AwesomeFilter(width: Int, height: Int) -> Int { + + var time = 10 //init i, store in memory + + for (var i = 0; i < width; i++) { + + time += 10 // init j each iteration of loop, store in memory + time += 3 // math operation i < width + time += 1 // access memory of i + time += 10 // write to memory + time += 3 //math operation + + for (var j = 0; j < height; j++) { + + time += 3 // math operation i < width + time += 1 // access memory of i + time += 10 // write to memory + time += 3 //math operation + time += 201 // 200 picosecond function, plus 1 psecond of memory access + } + + } + + + return time + +} + +print(AwesomeFilter(1000, height: 2000)) \ No newline at end of file From 6610445800969e67803dc49debbc82d9f317df47 Mon Sep 17 00:00:00 2001 From: jmeggesto Date: Fri, 15 Jan 2016 22:56:54 -0500 Subject: [PATCH 2/5] homework --- .DS_Store | Bin 6148 -> 8196 bytes .../Contents.swift | 5 ++ .../Contents.swift | 52 +++++++++++++++++- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/.DS_Store b/.DS_Store index 12a572ed6dc933c98f5fab447635662b078eb08c..4cec0e8a1359d1f645b933b82c42216d0041ac7a 100644 GIT binary patch delta 401 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMA$h$FMH}hr%jz7$c**Q2SHn1@A zZsuV*$;i3|s7iiv9h;pp7a&~>WEC-_GL!&uJcBPoB9N6aiA`d16bqk+ ziZIYS>ja(ri=%rD|O*`J4l VgAo$K43pz|rm`dX4y^qu69D0_Oq~D# delta 141 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jG%ZU^g=(*Jd7plZ>p>fHLxv z>xAqkuM^?s+`G{k$cKr@hzf7670O_otS_pxn4N<|kQpq=AixczT|p*pEd0(qnP0{e TWIh8E#4eEa44dP5<}d>QOOF`% diff --git a/HWfrom1-10-016(BigO).playground/Contents.swift b/HWfrom1-10-016(BigO).playground/Contents.swift index 09e00a3..4bc607f 100644 --- a/HWfrom1-10-016(BigO).playground/Contents.swift +++ b/HWfrom1-10-016(BigO).playground/Contents.swift @@ -142,6 +142,11 @@ peasant_mult(10, byNumber: 10) //time complexity: +let y = true +let x = false + + + //7) diff --git a/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift b/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift index bc0df91..bc1dab9 100644 --- a/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift +++ b/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift @@ -9,21 +9,69 @@ var str = "Hello, playground" Question 1: https://www.hackerrank.com/challenges/minimum-draws +in Python: + +import sys + +line = 1 +for lines in sys.stdin: + if line == 1: + line += 1 + continue + line += 1 + print(int(lines) +1) +constant time, after all we are only reading the int value of the line, the formula is number of pairs + 1 to determine worst-case for pairs of socks + +I did it in Python because I can't figure out how to read newlines in Swift, even with your example Ben + + Copy and paste your code: What is the big O runtime of your code?: Question 2: https://www.hackerrank.com/challenges/handshake + Copy and paste your code: -What is the big O runtime of your code?: +*/ + + +func factorial(num: Int) -> Int { + + + var product = 1 + for number in 1...num { + product *= number + } + + return product +} + +func combination(n: Int, r: Int) -> Int { + + + return factorial(n) / (factorial(r) * factorial(n-r)) + + +} + +print(combination(5, r: 2)) + +//it's a combination algorithm, only two people can shake hands at a time so n will be the number of people, and r will be 2 because two handshakers. + + +/* + +What is the big O runtime of your code?: IIRC my solution will be O(n) Question 3: https://www.hackerrank.com/challenges/connecting-towns Copy and paste your code: -What is the big O runtime of your code?: +//okay I didn't understand the format of this AT ALL, that site is barely readable, but you just multiply all the numbers of routes together + +What is the big O runtime of your code?: */ From c1cb23ef54373c4c224e8aaa46793a3e86ab94c4 Mon Sep 17 00:00:00 2001 From: jmeggesto Date: Thu, 21 Jan 2016 12:52:48 -0500 Subject: [PATCH 3/5] homework --- .DS_Store | Bin 8196 -> 8196 bytes .../Contents.swift | 117 +++++++++++++++++- 2 files changed, 112 insertions(+), 5 deletions(-) diff --git a/.DS_Store b/.DS_Store index 4cec0e8a1359d1f645b933b82c42216d0041ac7a..b508e5a7ee3e9468d3f412837c82a56587d9128b 100644 GIT binary patch delta 525 zcmZp1XmOa}&&awOPLmop4kPZf_ECPv55|Ws_M@Tx-4alivC}VJC2+T=03{K9^Enolx z)mcD_x)$W-ySSv3mLxMUTsl%A3buuE3%HSduvtcQE8}K%iEk{E8HL1$rT;cD0sx&e BY1#k) delta 64 zcmZp1XmOa}&&azmU^hP_?`9r>MJ)We`7SOgr6tJ>443xjEMl1aP&j__IuYTGr8k&1 RvrBwqnXD)x4-vS^1OUu-7VH23 diff --git a/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift b/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift index 5d51051..e1fcace 100644 --- a/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift +++ b/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift @@ -13,14 +13,121 @@ Link: https://docs.google.com/document/d/1XioaEqk6VqUPA-ccQhkqP3eAoDthxYyOM9vSPB 1) - - -2) +Given a partially filled in Sudoku board and a set of coordinates in that board pointing to an empty square, write a function that returns a list containing all numbers that the empty square could be. + +Input: sudokuBoard:[[Int?]]. (Each location on the board will be either be an Int from 1-9 or nil(empty cell)) +row: Int +col: Int + +func getValidNumbers(sudokuBoard:[[Int?]], row:Int, col:Int) -> [Int] { +return [Int]() +} + +*/ + +var sudoku = + [[2,7,1,9,5,4,6,8,3], + [5,9,3,6,2,8,1,4,7], + [4,6,8,1,3,7,2,5,9], + [7,3,6,4,1,5,8,9,2], + [1,5,9,8,6,2,3,7,4], + [8,4,2,3,7,9,5,6,1], + [9,8,5,2,4,1,7,3,6], + [6,1,7,5,9,3,4,2,8], + [3,2,4,7,8,6,9,1,5]] + +var incompleteSudoku = + + [[5,0,8,0,7,3,1,9,0], + [9,0,0,6,0,0,4,0,8], + [0,0,0,9,0,8,0,3,5], + [0,7,0,0,1,0,0,6,0], + [0,0,2,0,0,0,9,0,0], + [0,1,0,0,0,0,0,8,0], + [1,9,0,3,0,6,0,0,0], + [2,0,3,0,0,7,0,0,9], + [0,8,7,1,9,0,3,0,4]] + + +func getValidNumbers(sudokuBoard: [[Int]], row: Int, col: Int) -> [Int] { + + let topleftX = row - (row % 3) + let topleftY = col - (col % 3) + var grid = [Int]() + + for i in Range(start: topleftX, end: topleftX+3) { + + for j in Range(start: topleftY, end: topleftY+3) { + grid.append(sudokuBoard[i][j]) + } + + } + let complete = Set([1, 2, 3, 4, 5, 6, 7, 8, 9]) + + let column = sudokuBoard[col] + var rows = [Int]() + for cell in 0.. [[Int]] { + + + var temparr = [[Int]](count: 4, repeatedValue: []) + + for var i = 0; i < matrix.count; i++ { + + for var j = matrix.count - 1; j >= 0; j-- { + + temparr[i].append(matrix[j][i]) + print(j, i) + + } + + } + + + return temparr +} +print(rotateMatrix([ + [1,2,3,4], + [5,6,7,8], + [9,0,1,2], + [3,4,5,6]] +)) + + + +// 3) + +// split ABCD into two groups, AB and CD and compare those which will be fewer steps than checking all of them, then merge the two groups -*/ \ No newline at end of file From cbf7e9150d6d23972aeecdab1d0dbc9dcf439e34 Mon Sep 17 00:00:00 2001 From: jmeggesto Date: Tue, 26 Jan 2016 17:40:10 -0500 Subject: [PATCH 4/5] homework --- .DS_Store | Bin 8196 -> 10244 bytes .../Contents.swift | 20 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.DS_Store b/.DS_Store index b508e5a7ee3e9468d3f412837c82a56587d9128b..31548d6bd7675672e9a5b5c7449be1ccc4aa7175 100644 GIT binary patch delta 339 zcmZp1XbF&DU|?W$DortDU{C-uIe-{M3-C-V6q~50$SA%sU^hRjI8aDsvVef`WM(1J z$qpiXY)YL-LJFKauU7&22u0#TDK06cCCLm7m(Zm|C$AF`-pntsiG@*fvY%)W*f`Do zK+RyTNN&ChOzUwy4X~*&3AmXk5}VhFL^5w|_`xE`3|7sczzw8bL7v!H_?>w&zf7PA f6U1v^;}{tj3_uDe7s&K(o+xadrS{LVa?UnP)(5u%@Aay-w}$rB}PH# [Int] { + + + var left = values[0...1] + if left[0] > left[1] { + let t = left[0] + left[0] = left[1] + left[1] = t + } + var right = values[2...4] + if right[0] > right[1] { + let t = right[0] + right[0] = right[1] + right[1] = t + } + + + +} + // split ABCD into two groups, AB and CD and compare those which will be fewer steps than checking all of them, then merge the two groups From 58c33032b215bfcb200127a38e399789858ab122 Mon Sep 17 00:00:00 2001 From: jmeggesto Date: Thu, 28 Jan 2016 18:55:52 -0500 Subject: [PATCH 5/5] homework --- .DS_Store | Bin 10244 -> 8196 bytes .../FileFinder.xcodeproj/project.pbxproj | 246 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + FileFinder/FileFinder/main.swift | 38 +++ .../Contents.swift | 72 ++++- 5 files changed, 351 insertions(+), 12 deletions(-) create mode 100644 FileFinder/FileFinder.xcodeproj/project.pbxproj create mode 100644 FileFinder/FileFinder.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 FileFinder/FileFinder/main.swift diff --git a/.DS_Store b/.DS_Store index 82f7502bcb14a53e836fecf7fc343ca2421cb01c..047dd97d8488d10e428120263fa5252a41cea5ea 100644 GIT binary patch delta 247 zcmZn(XmOBWU|?W$DortDU;r^WfEYvza8E20o2aMAD6}zPH$S7$WCcN=$s0uZHm3kbDb#kNRJBn>9Wds1S3ovp3 delta 680 zcmZp1XbF&DU|?W$DortDU{C-uIe-{M3-C-V6q~50$SAcjU^hRb)MN!gpUD@5_%^2r zNHQ|2P8JX_W~`gsC#=FI`x~enCNNJxiQ|G0Pyks-Vse8hC+AKKak0q-BEpmF1-~&G zO>PjhvtrO=C}v1v&}A?OlEw^a3}!%_1QtnQFktXwaAzoFaL-9M3{K9^EdX1>p!gL? zlcGI0-^C@Rv?Q5<;nL3E55b0jwW|?l`{pDeMJ7g@$#Nn=_}uHpP{L5jP{!cO5Qyqt z)mcC*Nzsnv-Xj&FVE2Nx<8v>P?VAfksu?$y&R`W}2J2-|;0DsJpa|Yr_?>w&zf7PA z6C~O-KnfTcfFTV8lM7^enbR5kCp!p8;Ij%TVvvHy4^LnsISyOUFnBP8Gq^DnG2}Dk MG8h6AgCT=C0O)su$p8QV diff --git a/FileFinder/FileFinder.xcodeproj/project.pbxproj b/FileFinder/FileFinder.xcodeproj/project.pbxproj new file mode 100644 index 0000000..218573d --- /dev/null +++ b/FileFinder/FileFinder.xcodeproj/project.pbxproj @@ -0,0 +1,246 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 5D5011331C583C3700681B1E /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D5011321C583C3700681B1E /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 5D50112D1C583C3600681B1E /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 5D50112F1C583C3700681B1E /* FileFinder */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = FileFinder; sourceTree = BUILT_PRODUCTS_DIR; }; + 5D5011321C583C3700681B1E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 5D50112C1C583C3600681B1E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 5D5011261C583C3600681B1E = { + isa = PBXGroup; + children = ( + 5D5011311C583C3700681B1E /* FileFinder */, + 5D5011301C583C3700681B1E /* Products */, + ); + sourceTree = ""; + }; + 5D5011301C583C3700681B1E /* Products */ = { + isa = PBXGroup; + children = ( + 5D50112F1C583C3700681B1E /* FileFinder */, + ); + name = Products; + sourceTree = ""; + }; + 5D5011311C583C3700681B1E /* FileFinder */ = { + isa = PBXGroup; + children = ( + 5D5011321C583C3700681B1E /* main.swift */, + ); + path = FileFinder; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 5D50112E1C583C3600681B1E /* FileFinder */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5D5011361C583C3700681B1E /* Build configuration list for PBXNativeTarget "FileFinder" */; + buildPhases = ( + 5D50112B1C583C3600681B1E /* Sources */, + 5D50112C1C583C3600681B1E /* Frameworks */, + 5D50112D1C583C3600681B1E /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = FileFinder; + productName = FileFinder; + productReference = 5D50112F1C583C3700681B1E /* FileFinder */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 5D5011271C583C3600681B1E /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0720; + LastUpgradeCheck = 0720; + ORGANIZATIONNAME = "Jackie Meggesto"; + TargetAttributes = { + 5D50112E1C583C3600681B1E = { + CreatedOnToolsVersion = 7.2; + }; + }; + }; + buildConfigurationList = 5D50112A1C583C3600681B1E /* Build configuration list for PBXProject "FileFinder" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 5D5011261C583C3600681B1E; + productRefGroup = 5D5011301C583C3700681B1E /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 5D50112E1C583C3600681B1E /* FileFinder */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 5D50112B1C583C3600681B1E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5D5011331C583C3700681B1E /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 5D5011341C583C3700681B1E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 5D5011351C583C3700681B1E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + }; + name = Release; + }; + 5D5011371C583C3700681B1E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 5D5011381C583C3700681B1E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 5D50112A1C583C3600681B1E /* Build configuration list for PBXProject "FileFinder" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5D5011341C583C3700681B1E /* Debug */, + 5D5011351C583C3700681B1E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 5D5011361C583C3700681B1E /* Build configuration list for PBXNativeTarget "FileFinder" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5D5011371C583C3700681B1E /* Debug */, + 5D5011381C583C3700681B1E /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 5D5011271C583C3600681B1E /* Project object */; +} diff --git a/FileFinder/FileFinder.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/FileFinder/FileFinder.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..14e2c2f --- /dev/null +++ b/FileFinder/FileFinder.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/FileFinder/FileFinder/main.swift b/FileFinder/FileFinder/main.swift new file mode 100644 index 0000000..9ce479b --- /dev/null +++ b/FileFinder/FileFinder/main.swift @@ -0,0 +1,38 @@ +// +// main.swift +// FileFinder +// +// Created by Jackie Meggesto on 1/26/16. +// Copyright © 2016 Jackie Meggesto. All rights reserved. +// + +import Foundation + +import Foundation + +func findFile(name: String, atPath: String) -> String { + let fileManager = NSFileManager.defaultManager() + let contents = + try! fileManager.contentsOfDirectoryAtPath(atPath) + for fileOrDir in contents { + var isDir = ObjCBool(false); + let fullPath = atPath + "/" + fileOrDir + let exists = fileManager.fileExistsAtPath(fullPath, isDirectory: &isDir) + if exists && Bool(isDir) { + // YOUR CODE HERE + print("DIR: " + fileOrDir) + } else if exists { + // YOUR CODE HERE + print("FILE: " + fileOrDir) + } else { + print("NEITHER: " + fileOrDir) + } + } + return "NOT FOUND" +} + +// print(findFile("APITest.py", atPath: "/Users/jackiemeggesto/Documents")) + +print(UINT64_MAX) + + diff --git a/HWFrom1-24(Recursion).playground/Contents.swift b/HWFrom1-24(Recursion).playground/Contents.swift index 1c44504..e620946 100644 --- a/HWFrom1-24(Recursion).playground/Contents.swift +++ b/HWFrom1-24(Recursion).playground/Contents.swift @@ -9,17 +9,65 @@ Homework link: https://docs.google.com/document/d/1INvOynuggw69yLRNg3y-TPwBiYb3l -//Question 1 - - - - - - -//Question 2 - - - +/* Question 1 +Write an iterative (not recursive) fibonacci function that calculates the nth fibonacci number. How does its performance compare with the non-memoized recursive one (see Appendix A below), based on the number of iterations that Swift says it takes in the right margin? +*/ +func fib(n: Int) -> Int { + if (n == 0 || n == 1) { + return 1 + } + return fib(n - 1) + fib(n - 2) +} + +func iter_fib(n: Int) -> Int { + + var fibarr = [1, 1] + if n == 1 || n == 2 { + return fibarr[n-1] + } + while fibarr.count != n { + + fibarr.append(fibarr[fibarr.count - 1] + fibarr[fibarr.count - 2]) + + + + } + print(fibarr) + return fibarr[n-1] + + +} + + +//The iterative fibonacci sequence generator is much more efficient than the non-memoized recursive method. To generate the 50th Fibonacci number, the iterative method requires only 48 iterations, whereas the non-memoized function loops hundreds of thousands of times. + + +/* Question 2 +The engineers have been hard at work on the clumsy robot project, and have released a new API with a new tryStep method (see Appendix B). Now it returns an Int, which is -1 if the robot fell down a step, 0 if the robot stayed on the same step, or 1 if the robot went to the next step. Write a new stepUp method using this new tryStep method that works the same as before. +*/ -//Question 3 \ No newline at end of file +import Foundation + +var stepNum = 0 +func tryStep() -> Int { + let stepCount = Int(arc4random_uniform(3)) - 1 + stepNum += stepCount; + switch(stepCount) { + case -1: print("Ouch \(stepNum)") + case 1: print("Yay \(stepNum)") + default: print("Beep \(stepNum)") + } + return stepCount +} + +func stepUp() { + if tryStep() == 1 { + // We’re done! + return + } + // Now we’re two steps below where we want to be :-( + stepUp() + +} +//Question 3