diff --git a/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift b/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift index 13cc14e..60235f6 100644 --- a/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift +++ b/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift @@ -2,7 +2,6 @@ import UIKit -var str = "Hello, playground" /* @@ -12,15 +11,148 @@ Work on your solutions here. Link: https://docs.google.com/document/d/1INvOynuggw69yLRNg3y-TPwBiYb3lQZQiFUOxZKBwsY/edit#heading=h.za36ai6n5fth 1) +//Pseudocode +Boolean sudokuBoard(Grid grid){ +int row, col; +if(!FindUnassignedField(grid, row, col)) +return true; -2) +for(int num = 1; num <= 9; num++) { +if(isValidChoice(grid, row, col, num)) { / +grid(row, col) = num; +if(solveSudoku(grid)) return true; +grid(row, col) = UNASSIGNED; +} +} +return false; // no valid choice found, trigger backtracking +} -3) +2) func rotateNinety (arr: [[Int]]) -> [[Int]] { + for i in 0.. [Int] { + + for i in 0.. fourElements[i + 1] { + temp = fourElements[i + 1] + fourElements[i+1] = fourElements[i] + fourElements[i] = temp + + } + + if fourElements[fourElements.count - 2] > fourElements[fourElements.count - 1] { + temp = fourElements[fourElements.count - 2] + fourElements[fourElements.count - 2] = fourElements[fourElements.count - 1] + fourElements[fourElements.count - 1] = temp + + } + + return fourElements +} + + +var max = 0; +var min = 0; + +func findMinAndMax(fourElements) -> Int { + + for i in 0.. fourElements.count[i-1] { + var max = fourElements.count[i+1] + } else { + var max = fourElements.count[i-1] + } + } + + return min + return max +} + +*/ + + + + + + + + +//Simplest implementation of recursion +func fib(n: Int) -> Int { + if n < 2 { + return 1 + } + let a = n - 2 + let b = n - 1 + return fib(a) + fib(b) +} + +let values = (0..<10).map {i in fib(i)} +values + + + + + + + + + + + + + + + + + + + + +<<<<<<< HEAD +======= */ +>>>>>>> unit-4-assignments/master diff --git a/HWFrom1-24(Recursion).playground/Contents.swift b/HWFrom1-24(Recursion).playground/Contents.swift index 1c44504..7c582cd 100644 --- a/HWFrom1-24(Recursion).playground/Contents.swift +++ b/HWFrom1-24(Recursion).playground/Contents.swift @@ -12,14 +12,290 @@ Homework link: https://docs.google.com/document/d/1INvOynuggw69yLRNg3y-TPwBiYb3l //Question 1 +var i = 0 +var j = 1 +var n = Int () +var k = Int () +var temp = 0 +func fibIteration (var i: Int) -> Int { + for _ in 0.. 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() { + switch tryStep() { + case1: + 0 + default: + stepUp() + case -1: + stepUp() + stepUp() + +} + +func stepUp() { +if tryStep() { +// We’re done! +return +} +// Now we’re two steps below where we want to be :-( +stepUp() + + + + + + +3) + +let result = findFile(name, atPath: fullPath) + +if result != "NOT FOUND" { + return result +} + +if fileOrDir === name +{ + return fullPath +} + + + + +///////////////////////Merge sort///////////////////////// + +func mergeSort(values: [Int]) -> [Int] { + +//check length of values, return values if count is less than 2 +// Split values into left and right (roughly equal size) + +let array = [1,2,3,4] +let n = values.count + + +n + +n / 2 + +if n < 2 { + return values + +} + + +//slice in swift +var left = Array(values[0.. [Int] { +// Iterate over both left and right at the same time + + var i = 0 + var j = 0 + while i < left.count || j < right.count { + if j >= right.count || left[i] < right[j] } + result.append(left[i]) + i += 1 + } else if j < right.count { + result.append(right[j]) + j += 1 + + } + } + + return result + +} + +mergeSort([10,2,6,5]) + +merge(withLeftArray: [3,6], andRightArray: [1,2]) + + + + + + +/////////////MERGE SORT 2////////////////// + + + + + + + + + + + + + +////////////example of recursion///////////////// + +func printAllElements(values: [Int]) { + for value in values { + print(value) + } +} + + +func printAllElementsRecursive(values: [Int]) { + printElementsHelper(values, index: 0) +} + + +func printElementsHelper(values: [Int], index: Int) { + print(values[index]) + printElementsHelper(values, index: index + 1) +} + + + +let values = [10,20,30] +printElementsHelper(values, index: 0) + + + + + + + + + + + + + + +for i in 0.. [Int] { +// Iterate over both left and right at the same time + +// Compare pairs of values in left and right + +// Take the minimum of the two and add it to the result + +return [] // <-- change this +} + + + + + + + + + + + + + + + + + + -//Question 3 \ No newline at end of file diff --git a/HWFrom1-24(Recursion).playground/contents.xcplayground b/HWFrom1-24(Recursion).playground/contents.xcplayground index 5da2641..ee7c14f 100644 --- a/HWFrom1-24(Recursion).playground/contents.xcplayground +++ b/HWFrom1-24(Recursion).playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/HWFrom1-28-16(Merge Sort).playground/Contents.swift b/HWFrom1-28-16(Merge Sort).playground/Contents.swift index afdc1b6..aa41087 100644 --- a/HWFrom1-28-16(Merge Sort).playground/Contents.swift +++ b/HWFrom1-28-16(Merge Sort).playground/Contents.swift @@ -4,3 +4,28 @@ //Insert code here: + +var array = [1, 2, 6, 4, 7] +swap(&array[0], &array[1]) +array // [2, 1] + + +func selectionSort(var arr: [Int]) -> [Int] +{ + var minIndex = 0 + + for i in 0..= lastIdx { return } + // partition + let splitPoint = partition(&arr, firstIdx: firstIdx, lastIdx: lastIdx) + // quickSort on leftHalf + quickSort(&arr, firstIdx: firstIdx, lastIdx: splitPoint - 1) + // quickSort on rightHalf + quickSort(&arr, firstIdx: splitPoint + 1, lastIdx: lastIdx) +} + +func quickSort(inout arr: [Int]) { + quickSort(&arr, firstIdx: 0, lastIdx: arr.count-1) +} + +func partition(inout arr: [Int], firstIdx: Int, lastIdx: Int) -> Int { + // set pivotValue to firstElement + let pivotValue = arr[firstIdx] + // set leftMark + var leftMark = firstIdx + 1 + // set rightMark + var rightMark = lastIdx + /* + as leftMark and rightMark close in on each other, + swap the items that are greater than the pivot value + on the left side with the items that are less than the pivot + value on the right side. Stop when rightMark crosses leftMark + */ + while leftMark <= rightMark { + while arr[leftMark] < pivotValue && leftMark <= rightMark { + leftMark += 1 + } + while arr[rightMark] > pivotValue && leftMark <= rightMark{ + rightMark -= 1 + } + if leftMark < rightMark { + swap(&arr[leftMark], &arr[rightMark]) + } + } + // set the correct value at the splitPoint + if firstIdx != rightMark { + swap(&arr[firstIdx], &arr[rightMark]) + } + return rightMark // return the splitPoint +} + +var numbers = [22, 59, 38, 93,95, 0, 34, 58, 72, 15] + +quickSort(&numbers) + + + +//4) Write a function to generate an array of random numbers bounded between 1..<10,000 of size 10,000. + +// create an array of 0 through 1000 +//var nums = Array(0...10000) + +// remove the blacklist number +//nums.removeAtIndex(nums.indexOf(8)!) +// +//var randoms = [Int]() +//for _ in 1...10000 { +// let index = Int(arc4random_uniform(UInt32(10000))) +// randoms.append(nums[index]) +// nums.removeAtIndex(index) +//} + + + +//5)The Merge Sort is usually required while sorting a too large set to hold or handle in internal memory. It divides the set into a number of subsets of one element and then repeatedly merge the subsets into increasingly larger subsets with the elements sorted correctly until one set is left. Sorting happens as elements are being popped off from the large sets. + +//The Quick Sort operates by selecting a single element from the set and labelling it the pivot. The set is then reorder to ensure that all elements of lesser value than the pivot come before it and all elements of greater value come after it. This operation is recursively applied to the subsets on both sides of pivot until the entire set is sorted. Sorting happens as the recursive calls are being pushed onto the stack. + + +//6) +// +//var paren = [ “[“,"]”,”{“,”}”,”(“,”)” ] +// +// func isBalanced(paren: [String]) -> Bool { +// for i in 0.. Int { + var totalSum = N*(N+1)/2 //Gaussian sum-sum everything up from 1 to 10 for example + var totalSumOfList = 0 + for i in list { + totalSumOfList += i + } + + return totalSum - totalSumOfList +} + + + + + +//2)Given a list of size N containing numbers 1 - N (inclusive). return true if there are duplicates, false if not + +var list3 = [Int]() +list3.sort() + +func hasDuplicates(list3: [Int]) -> Bool { + for i in 0.. [Int] { + var com = [Int]() + for i in 0.. Int { + var min = Int.max + + for i in 0.. Int? { + var commonElements = getCommonValues(list1, list2: list2) + if (commonElements.count == 0) { + return nil + } + var smallestVal = getSmallestValue(commonElements) + + return smallestVal +} + +var answer = smallestCommonVal(list1, list2: list2) +print(answer) + + + + + +//4)Check to see if an integer is a palindrome don’t use casting + +func isPalindrome(var num: Int) -> Bool { + let originalNum = num + var finalNum = 0 + while(num > 0) { + finalNum *= 10 + finalNum += num % 10 + num /= 10 + } + return finalNum == originalNum +} + +let num = 21012 +isPalindrome(num) -4) -*/ diff --git a/HWfrom1-10-016(BigO).playground/Contents.swift b/HWfrom1-10-016(BigO).playground/Contents.swift index 2040d38..8b137ca 100644 --- a/HWfrom1-10-016(BigO).playground/Contents.swift +++ b/HWfrom1-10-016(BigO).playground/Contents.swift @@ -12,18 +12,177 @@ https://docs.google.com/document/d/1aF1imJUVahCSJAuN1OEm5lQXwpSFaAmVmAETKMM6PLQ/ 1) +//// 1a) + [math] 1000 * 3 + [math] 1000 * 2000 * 3 + [memory] 1000 * 2000 * 2 + [storage] 1000 * 2000 * 10 + [filter] 1000 * 2000 * 200 + 430,003,000 picoseconds or 4.3 * 10^7 + +//// 1b) + [math] n * 3 + [math] n * m * 3 + [memory] n * m * 2 + [storage] n * m * 10 + [filter] n * m * 200 + (3n)+(3nm)+(2nm)+(10nm)+(200nm) + (3n)+(215nm) + +//// 1c) O(n^2) + +//// 1d) O(n^4) +*/ + + + + +/* +2)If foo(xs) is a function with time complexity n (where n is the size of the input array), and bar(xs) is a function with time complexity n2, what is the time complexity of each of the following snippets of code or algorithms? +///// 2a) +for (int i = 0; i < n; i++) { //n + for (int j = 0; j < n; j++) { // n + foo(xs); // n + } +} +n * n * n = n^3 +for (int i = 0; i < n; i++) { // n + for (int j = 0; j < n; j++) { // n + bar(xs); // n^2 + } +} +n * n * n^2 = n^4 +for (int i = 0; i < n; i++) { // n + for (int j = 0; j < n; j++) { // n + // do cool stuff + } +} + + n * n = n^2 + + + + + +///// 2b) +int frobnicate(ys, m) { + if (m == 0) { + return 0; + } + return ys[m] + frobnicate(ys, m - 1); +} +frobnicate(xs, n); + + +Big O notation -> 0(n); + + +/////2c) +BOOL betterHasDuplicates(int xs[], int n) { +for (int i = 0; i < n; i++) { //n +for (int j = i; j < n; j++) { //n * n +if (i != j && xs[i] == xs[j]) { //n +return YES; +} +} +} +return NO; +} + + n * n^2 * n = n ^4 + +//MERGE SORT +list1 = [Int]() +func mergeSort (list1, [Int]) -> [Int]{ + +// split array in half +var middle = list1.count/ 2 +var right = [Int](); +var left = [Int](); + +for i in 0.. Int{ + + if (num == 0){ + return 1; + } + + else { + return (num * factorial(num - 1)) + } +} + + + + 5) +func multiplyTheseTwo(num1: Int, num2: Int) -> Int { + + let baseNum = num1 + let multiplierNum = num2 + var product = 0 + + for (var i = 0; i < multiplierNum; i++){ + product += baseNum + print(product) + } + + return product +} + 6) -7) +func russianPeasant(var left_num : Int, var right_num : Int) -> Int { +var product = 0 +if(left_num % 2 != 0) +{ +product += right_num +} +while(left_num > 1) +{ +left_num /= 2 +right_num *= 2 +if( left_num % 2 != 0) +{ +product += right_num +} +} +return product +} + + +Big O: logn <--- correct answer + ///when you double something and then add something, it's logn + +7)Don't really know how to do this. Will continue working on this */ diff --git a/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift b/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift index bc0df91..fa2b75f 100644 --- a/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift +++ b/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift @@ -10,20 +10,70 @@ var str = "Hello, playground" Question 1: https://www.hackerrank.com/challenges/minimum-draws Copy and paste your code: +let testCases = Int(readLine(stripNewline: true)!)! +for i in 0...n{ +//new line +let n = Int(readLine(stripNewline: true)!)! +print(n+1) +} -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: +let testCases = Int(readLine(stripNewline: true)!)! +for i in 0...n{ +//n represents number of people +let n = Int(readLine(stripNewline: true)!)! +print((n *(n-1))/2) +} -What is the big O runtime of your code?: +What is the big O runtime of your code?: 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?: +let testCases = Int(readLine(stripNewline: true)!)! +for i in 0...testCases { +let towns = Int(readLine(stripNewline: true)!)! +var routes = [Int]() +var result = 0; + +for i in 0.. Int { + let input = readLine() + let num = Int(input!) + return num! + +*/ diff --git a/homeworkJan24/homeworkJan24.xcodeproj/project.pbxproj b/homeworkJan24/homeworkJan24.xcodeproj/project.pbxproj new file mode 100644 index 0000000..a4d1081 --- /dev/null +++ b/homeworkJan24/homeworkJan24.xcodeproj/project.pbxproj @@ -0,0 +1,243 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 5F0F4D531C5A84C900BB2D9A /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F0F4D521C5A84C900BB2D9A /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 5F0F4D4D1C5A84C900BB2D9A /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 5F0F4D4F1C5A84C900BB2D9A /* homeworkJan24 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = homeworkJan24; sourceTree = BUILT_PRODUCTS_DIR; }; + 5F0F4D521C5A84C900BB2D9A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 5F0F4D4C1C5A84C900BB2D9A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 5F0F4D461C5A84C900BB2D9A = { + isa = PBXGroup; + children = ( + 5F0F4D511C5A84C900BB2D9A /* homeworkJan24 */, + 5F0F4D501C5A84C900BB2D9A /* Products */, + ); + sourceTree = ""; + }; + 5F0F4D501C5A84C900BB2D9A /* Products */ = { + isa = PBXGroup; + children = ( + 5F0F4D4F1C5A84C900BB2D9A /* homeworkJan24 */, + ); + name = Products; + sourceTree = ""; + }; + 5F0F4D511C5A84C900BB2D9A /* homeworkJan24 */ = { + isa = PBXGroup; + children = ( + 5F0F4D521C5A84C900BB2D9A /* main.swift */, + ); + path = homeworkJan24; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 5F0F4D4E1C5A84C900BB2D9A /* homeworkJan24 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5F0F4D561C5A84C900BB2D9A /* Build configuration list for PBXNativeTarget "homeworkJan24" */; + buildPhases = ( + 5F0F4D4B1C5A84C900BB2D9A /* Sources */, + 5F0F4D4C1C5A84C900BB2D9A /* Frameworks */, + 5F0F4D4D1C5A84C900BB2D9A /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = homeworkJan24; + productName = homeworkJan24; + productReference = 5F0F4D4F1C5A84C900BB2D9A /* homeworkJan24 */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 5F0F4D471C5A84C900BB2D9A /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0700; + ORGANIZATIONNAME = c4q; + TargetAttributes = { + 5F0F4D4E1C5A84C900BB2D9A = { + CreatedOnToolsVersion = 7.0; + }; + }; + }; + buildConfigurationList = 5F0F4D4A1C5A84C900BB2D9A /* Build configuration list for PBXProject "homeworkJan24" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 5F0F4D461C5A84C900BB2D9A; + productRefGroup = 5F0F4D501C5A84C900BB2D9A /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 5F0F4D4E1C5A84C900BB2D9A /* homeworkJan24 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 5F0F4D4B1C5A84C900BB2D9A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5F0F4D531C5A84C900BB2D9A /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 5F0F4D541C5A84C900BB2D9A /* 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; + 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.10; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 5F0F4D551C5A84C900BB2D9A /* 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; + 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.10; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + }; + name = Release; + }; + 5F0F4D571C5A84C900BB2D9A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 5F0F4D581C5A84C900BB2D9A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 5F0F4D4A1C5A84C900BB2D9A /* Build configuration list for PBXProject "homeworkJan24" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5F0F4D541C5A84C900BB2D9A /* Debug */, + 5F0F4D551C5A84C900BB2D9A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 5F0F4D561C5A84C900BB2D9A /* Build configuration list for PBXNativeTarget "homeworkJan24" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5F0F4D571C5A84C900BB2D9A /* Debug */, + 5F0F4D581C5A84C900BB2D9A /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 5F0F4D471C5A84C900BB2D9A /* Project object */; +} diff --git a/homeworkJan24/homeworkJan24.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/homeworkJan24/homeworkJan24.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..2944ca5 --- /dev/null +++ b/homeworkJan24/homeworkJan24.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/homeworkJan24/homeworkJan24/main.swift b/homeworkJan24/homeworkJan24/main.swift new file mode 100644 index 0000000..552492f --- /dev/null +++ b/homeworkJan24/homeworkJan24/main.swift @@ -0,0 +1,38 @@ +// +// main.swift +// homeworkJan24 +// +// Created by Zoufishan Mehdi on 1/28/16. +// Copyright © 2016 c4q. All rights reserved. +// + +import Foundation + +print("Hello, World!") + +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) { + // fileOrDir = fileManager.contentsOfDirectoryAtPath(atPath) + contentsOfDirectoryAtPath(atPath) + print("DIR: " + fileOrDir) + } else if exists { + //file.append(atPath) + fileExistsAtPath(atPath, + isDirectory) + print("FILE: " + fileOrDir) + } else { + print("NEITHER: " + fileOrDir) + } + } + return "NOT FOUND" +} + +print(findFile("awesome-idea.txt", atPath: "/Users/zinfandel/Documents")) +