diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/HW-1-23/Homework.xcodeproj/project.pbxproj b/HW-1-23/Homework.xcodeproj/project.pbxproj new file mode 100755 index 0000000..b28c4e7 --- /dev/null +++ b/HW-1-23/Homework.xcodeproj/project.pbxproj @@ -0,0 +1,246 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 3D7466751C59B9B9003A3C9A /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D7466741C59B9B9003A3C9A /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 3D74666F1C59B9B8003A3C9A /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 3D7466711C59B9B9003A3C9A /* Homework */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Homework; sourceTree = BUILT_PRODUCTS_DIR; }; + 3D7466741C59B9B9003A3C9A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 3D74666E1C59B9B8003A3C9A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 3D7466681C59B9B8003A3C9A = { + isa = PBXGroup; + children = ( + 3D7466731C59B9B9003A3C9A /* Homework */, + 3D7466721C59B9B9003A3C9A /* Products */, + ); + sourceTree = ""; + }; + 3D7466721C59B9B9003A3C9A /* Products */ = { + isa = PBXGroup; + children = ( + 3D7466711C59B9B9003A3C9A /* Homework */, + ); + name = Products; + sourceTree = ""; + }; + 3D7466731C59B9B9003A3C9A /* Homework */ = { + isa = PBXGroup; + children = ( + 3D7466741C59B9B9003A3C9A /* main.swift */, + ); + path = Homework; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 3D7466701C59B9B8003A3C9A /* Homework */ = { + isa = PBXNativeTarget; + buildConfigurationList = 3D7466781C59B9B9003A3C9A /* Build configuration list for PBXNativeTarget "Homework" */; + buildPhases = ( + 3D74666D1C59B9B8003A3C9A /* Sources */, + 3D74666E1C59B9B8003A3C9A /* Frameworks */, + 3D74666F1C59B9B8003A3C9A /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Homework; + productName = Homework; + productReference = 3D7466711C59B9B9003A3C9A /* Homework */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 3D7466691C59B9B8003A3C9A /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0720; + LastUpgradeCheck = 0720; + ORGANIZATIONNAME = apps; + TargetAttributes = { + 3D7466701C59B9B8003A3C9A = { + CreatedOnToolsVersion = 7.2; + }; + }; + }; + buildConfigurationList = 3D74666C1C59B9B8003A3C9A /* Build configuration list for PBXProject "Homework" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 3D7466681C59B9B8003A3C9A; + productRefGroup = 3D7466721C59B9B9003A3C9A /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 3D7466701C59B9B8003A3C9A /* Homework */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 3D74666D1C59B9B8003A3C9A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3D7466751C59B9B9003A3C9A /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 3D7466761C59B9B9003A3C9A /* 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.10; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 3D7466771C59B9B9003A3C9A /* 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.10; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + }; + name = Release; + }; + 3D7466791C59B9B9003A3C9A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 3D74667A1C59B9B9003A3C9A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 3D74666C1C59B9B8003A3C9A /* Build configuration list for PBXProject "Homework" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3D7466761C59B9B9003A3C9A /* Debug */, + 3D7466771C59B9B9003A3C9A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 3D7466781C59B9B9003A3C9A /* Build configuration list for PBXNativeTarget "Homework" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3D7466791C59B9B9003A3C9A /* Debug */, + 3D74667A1C59B9B9003A3C9A /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = 3D7466691C59B9B8003A3C9A /* Project object */; +} diff --git a/HW-1-23/Homework.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/HW-1-23/Homework.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100755 index 0000000..bfc050b --- /dev/null +++ b/HW-1-23/Homework.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/HW-1-23/Homework/main.swift b/HW-1-23/Homework/main.swift new file mode 100755 index 0000000..3de635d --- /dev/null +++ b/HW-1-23/Homework/main.swift @@ -0,0 +1,31 @@ +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) { + print("DIR: " + fileOrDir) + let result = findFile(name, atPath: fullPath) + if result != "NOT FOUND" + { + return result + } + } else if exists { + if fileOrDir == name { + return fullPath + } + print("FILE: " + fileOrDir) + } else { + print("NEITHER: " + fileOrDir) + } + } + return "NOT FOUND" +} + + +print(findFile("gandalf.jpeg", atPath: "/Users/Mima/Downloads")) \ No newline at end of file diff --git a/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift b/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift old mode 100644 new mode 100755 index 13cc14e..6543796 --- a/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift +++ b/HWFrom1-17-16(Lists and Sorts).playground/Contents.swift @@ -1,26 +1,281 @@ -//: Playground - noun: a place where people can play -import UIKit +// 1. +var sudokuBoard = [ + [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, 0, 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]] -var str = "Hello, playground" -/* +// vertical box constraint +func verticalConstraintBox(row: Int) ->[Int] { + var maxConstraint: Int = 0 + var minConstraint: Int = 0 + var constraints: [Int] = [] + for i in 0.. Set { + var verticalConstraintsBox = verticalConstraints + var maxHC: Int = 0 + var minHC: Int = 0 + + if ((column + 1) % 3 == 0){ + maxHC = column + 1 + minHC = column - 2 + } + else if ((column + 1) % 3 == 1) { + maxHC = column + 3 + minHC = column + } + else if ((column + 1) % 3 == 2) { + maxHC = column + 2 + minHC = column - 1 + } + + var arr1 = Array((sudokuBoard[verticalConstraintsBox[0]])[minHC.. = [] + + for i in 0..) -> Set { + var notPossibleOutcomes: Set = [] + for i in 0..) -> Set { + var notPossibleOutcomes: Set = [] + for i in 0..>>>>>> df0dff8f1511200af5eae06e949d0d5f90c95b74 -1) +// get user input and return the possible # for that empty space +func getCoordinatesAndReturnPossibleMoves() -> Set { + print("Please enter valid input(s) from 1-9") + var row = Int(readLine()!)! // get user input + var column = Int(readLine()!)! + var inputsWithinRangeAndSpaceEmpty: Bool = false + repeat { + if ((row > 0 && row < 10) + && (column > 0 && column < 10) + && (sudokuBoard[row][column] == 0)){ // check if input is valid + inputsWithinRangeAndSpaceEmpty = true + } + else { + print("Please enter valid input(s)") + row = Int(readLine()!)! + column = Int(readLine()!)! + } + }while inputsWithinRangeAndSpaceEmpty == false // repeat if the input is invalid + + let sudokuSet: Set = [1,2,3,4,5,6,7,8,9] + let horizontalSet: Set = horizontalCheckSudoku(2, column: 2, arr:sudokuSet) + let verticalSet: Set = verticalCheckSudoku(2, column: 2, arr: sudokuSet) + let boxSet: Set = totalBoxConstraints(column, verticalConstraints: verticalConstraintBox(row)) + + let horizontalAndVertical: Set = horizontalSet.union(verticalSet) + let notPossibleOutcomes: Set = horizontalAndVertical.union(boxSet) + + let finalSet: Set = sudokuSet.subtract(notPossibleOutcomes) + + return finalSet +} +//print(getCoordinatesAndReturnPossibleMoves()) -2) +func matrixRotate() { + // matrix board + var matrix = [ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 0, 1, 2], + [3, 4, 5, 6]] + + var new90RotatedMatrix = [ + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0]] + var num = matrix.count + var count = 0 + repeat { + + for i in 0.. Int(letters[i + 1])){ + firstMin = Int(letters[i+1])! + firstMax = Int(letters[i])! + } else { + firstMin = Int(letters[i])! + firstMax = Int(letters[i+1])! + } + } + else if (i > middlePoint && i < letters.count - 1) { + if (Int(letters[i]) > Int(letters[i + 1])){ + secMin = Int(letters[i+1])! + secMax = Int(letters[i])! + } else { + secMin = Int(letters[i])! + secMax = Int(letters[i+1])! + } + } + + if (firstMin != 0 && secMin != 0){ + if (firstMin > secMin){ + finalMin = secMin + var newChar = Character(UnicodeScalar(finalMin)) + letters[letters.count - letters.count] = String(newChar) + print(letters[letters.count - letters.count]) + midMin = firstMin + } else { + finalMin = firstMin + var newChar = Character(UnicodeScalar(finalMin)) + letters[letters.count - letters.count] = String(newChar) + print(letters[letters.count - letters.count]) + midMin = secMin + } + } + + if (firstMax != 0 && secMax != 0){ + if (firstMax > secMax){ + finalMax = firstMax + var newChar = Character(UnicodeScalar(finalMax)) + letters[i] = String(newChar) + print(letters[i]) + midMax = secMax + } else { + finalMax = secMax + var newChar = Character(UnicodeScalar(finalMax)) + letters[i] = String(newChar) + print(letters[i]) + midMax = firstMax + } + } + + if (midMax != 0 && midMin != 0){ + if (midMax > midMin){ + letters[letters.count - 2] = String(Character(UnicodeScalar(midMax))) + letters[0 + 1] = String(Character(UnicodeScalar(midMin))) + } else { + letters[letters.count - 2] = String(Character(UnicodeScalar(midMin))) + letters[0 + 1] = String(Character(UnicodeScalar(midMax))) + } + } +} + +print(letters) + +<<<<<<< HEAD +======= */ +>>>>>>> df0dff8f1511200af5eae06e949d0d5f90c95b74 diff --git a/HWFrom1-17-16(Lists and Sorts).playground/contents.xcplayground b/HWFrom1-17-16(Lists and Sorts).playground/contents.xcplayground old mode 100644 new mode 100755 diff --git a/HWFrom1-17-16(Lists and Sorts).playground/playground.xcworkspace/contents.xcworkspacedata b/HWFrom1-17-16(Lists and Sorts).playground/playground.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/HWFrom1-17-16(Lists and Sorts).playground/timeline.xctimeline b/HWFrom1-17-16(Lists and Sorts).playground/timeline.xctimeline old mode 100644 new mode 100755 diff --git a/HWFrom1-24(Recursion).playground/Contents.swift b/HWFrom1-24(Recursion).playground/Contents.swift old mode 100644 new mode 100755 index 1c44504..22488f9 --- a/HWFrom1-24(Recursion).playground/Contents.swift +++ b/HWFrom1-24(Recursion).playground/Contents.swift @@ -9,17 +9,63 @@ Homework link: https://docs.google.com/document/d/1INvOynuggw69yLRNg3y-TPwBiYb3l -//Question 1 - - - - - - -//Question 2 - - - - - -//Question 3 \ No newline at end of file +//1 Write without the recursion + +func fib(n: Int) -> Int { + print("X") + if (n == 0 || n == 1) { + return 1 + } + return fib(n - 1) + fib(n - 2) +} + +func fibTest (num: Int) -> Int { + var xn = 0 + var n1 = 0 + var n2 = 1 + print(n1) + print(n2) + for(var i = 2; i < num; i++){ + xn = n1 + n2 + print(xn) + n1 = n2 + n2 = xn + } + + return num +} + +fibTest(5) + + +//2 + +/* HW */ +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() { + let stepCounts = tryStep() + if (stepCounts == -1){ + print("stepCount -1") + stepUp() + print("stepCount -1") + stepUp() + } + else if (stepCounts == 0){ + stepUp() + } +} + +stepUp() \ No newline at end of file diff --git a/HWFrom1-24(Recursion).playground/contents.xcplayground b/HWFrom1-24(Recursion).playground/contents.xcplayground old mode 100644 new mode 100755 diff --git a/HWFrom1-24(Recursion).playground/playground.xcworkspace/contents.xcworkspacedata b/HWFrom1-24(Recursion).playground/playground.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/HWFrom1-24(Recursion).playground/timeline.xctimeline b/HWFrom1-24(Recursion).playground/timeline.xctimeline old mode 100644 new mode 100755 diff --git a/HWFrom1-28-16(Merge Sort).playground/Contents.swift b/HWFrom1-28-16(Merge Sort).playground/Contents.swift old mode 100644 new mode 100755 index afdc1b6..cb0b670 --- a/HWFrom1-28-16(Merge Sort).playground/Contents.swift +++ b/HWFrom1-28-16(Merge Sort).playground/Contents.swift @@ -4,3 +4,49 @@ //Insert code here: + + + +var listOfNumbers = [7, 8, 3, 10, 5] +var index = 0 +var arrayCount = listOfNumbers.count +func insertionSort(inout values: [Int]) { + print(listOfNumbers) + + func keepSorting(var i: Int) -> Int { + print("i sorting") + + if (i < arrayCount) { + print("i index \(i)") + print("num in i \(listOfNumbers[i])") + func compare(var j: Int) -> Int { + print("j sorting") + if (j < arrayCount) { + if listOfNumbers[j] > listOfNumbers[i] { + swap(&listOfNumbers[j], &listOfNumbers[i]) + } + print("j index: \(j)") + print("num in j: \(listOfNumbers[j])") + j++ + return compare(j) + } + + return j + } + + compare(i) + + i++ + return keepSorting(i) + } + + return i + } + + keepSorting(index) +} + + +insertionSort(&listOfNumbers) +print(listOfNumbers) + diff --git a/HWFrom1-28-16(Merge Sort).playground/contents.xcplayground b/HWFrom1-28-16(Merge Sort).playground/contents.xcplayground old mode 100644 new mode 100755 diff --git a/HWFrom1-28-16(Merge Sort).playground/playground.xcworkspace/contents.xcworkspacedata b/HWFrom1-28-16(Merge Sort).playground/playground.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/HWFrom1-28-16(Merge Sort).playground/timeline.xctimeline b/HWFrom1-28-16(Merge Sort).playground/timeline.xctimeline old mode 100644 new mode 100755 diff --git a/HWFrom1-30-16(QuickSort+Lists+Queues).playground/Contents.swift b/HWFrom1-30-16(QuickSort+Lists+Queues).playground/Contents.swift old mode 100644 new mode 100755 diff --git a/HWFrom1-30-16(QuickSort+Lists+Queues).playground/contents.xcplayground b/HWFrom1-30-16(QuickSort+Lists+Queues).playground/contents.xcplayground old mode 100644 new mode 100755 diff --git a/HWFrom1-30-16(QuickSort+Lists+Queues).playground/playground.xcworkspace/contents.xcworkspacedata b/HWFrom1-30-16(QuickSort+Lists+Queues).playground/playground.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/HWFrom1-30-16(QuickSort+Lists+Queues).playground/timeline.xctimeline b/HWFrom1-30-16(QuickSort+Lists+Queues).playground/timeline.xctimeline old mode 100644 new mode 100755 diff --git a/HWFrom1-31-16(Sets and HashMaps).playground/Contents.swift b/HWFrom1-31-16(Sets and HashMaps).playground/Contents.swift old mode 100644 new mode 100755 diff --git a/HWFrom1-31-16(Sets and HashMaps).playground/contents.xcplayground b/HWFrom1-31-16(Sets and HashMaps).playground/contents.xcplayground old mode 100644 new mode 100755 diff --git a/HWFrom1-31-16(Sets and HashMaps).playground/playground.xcworkspace/contents.xcworkspacedata b/HWFrom1-31-16(Sets and HashMaps).playground/playground.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/HWFrom1-31-16(Sets and HashMaps).playground/timeline.xctimeline b/HWFrom1-31-16(Sets and HashMaps).playground/timeline.xctimeline old mode 100644 new mode 100755 diff --git a/HWFrom2-05-16(Trees).playground/Contents.swift b/HWFrom2-05-16(Trees).playground/Contents.swift old mode 100644 new mode 100755 diff --git a/HWFrom2-05-16(Trees).playground/contents.xcplayground b/HWFrom2-05-16(Trees).playground/contents.xcplayground old mode 100644 new mode 100755 diff --git a/HWFrom2-05-16(Trees).playground/playground.xcworkspace/contents.xcworkspacedata b/HWFrom2-05-16(Trees).playground/playground.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/HWFrom2-05-16(Trees).playground/timeline.xctimeline b/HWFrom2-05-16(Trees).playground/timeline.xctimeline old mode 100644 new mode 100755 diff --git a/HWfrom1-09-16(SwiftIntro).playground/Contents.swift b/HWfrom1-09-16(SwiftIntro).playground/Contents.swift old mode 100644 new mode 100755 index 488e9ed..08b0d38 --- a/HWfrom1-09-16(SwiftIntro).playground/Contents.swift +++ b/HWfrom1-09-16(SwiftIntro).playground/Contents.swift @@ -1,23 +1,83 @@ -//: Playground - noun: a place where people can play +//: 01-09 Saturday Homework - Instructor: Linus +/*: -import UIKit +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. -var str = "Hello, playground" +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 +func findMissingNumber(N: Int, list: [Int]) -> Int { + list.sort({$0 < $1}) + var j = 0 + var missingNum = 0 -1) + for i in (0.. Int? { + let setOne = Set(listOne) + let setTwo = Set(listTwo) + let num = setOne.intersect(setTwo).minElement() + return num +} + +//: ### 4 + +struct Stack { + private var items:[T] + var count: Int { + get { + return items.count + } + } + + mutating func push(element: T) { + items.append(element) + } + + mutating func pop() -> T { + return items.removeLast() + } +} + +func isPalindrome(word: String) -> Bool { + var stack = Stack(items: Array(word.characters)) + var reverseStack = Stack(items: Array(word.characters).reverse()) + + for _ in 0.. - + \ No newline at end of file diff --git a/HWfrom1-09-16(SwiftIntro).playground/playground.xcworkspace/contents.xcworkspacedata b/HWfrom1-09-16(SwiftIntro).playground/playground.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/HWfrom1-09-16(SwiftIntro).playground/timeline.xctimeline b/HWfrom1-09-16(SwiftIntro).playground/timeline.xctimeline old mode 100644 new mode 100755 diff --git a/HWfrom1-10-016(BigO).playground/Contents.swift b/HWfrom1-10-016(BigO).playground/Contents.swift old mode 100644 new mode 100755 index 2040d38..e8efe2f --- a/HWfrom1-10-016(BigO).playground/Contents.swift +++ b/HWfrom1-10-016(BigO).playground/Contents.swift @@ -1,30 +1,326 @@ -//: Playground - noun: a place where people can play import UIKit +import Foundation -var str = "Hello, playground" +//: Homework - 01/10 (Sunday) Big-O -/* +/*: +### 1. +With my new top of the line XJ452 supercomputer, memory access takes 1 picosecond, +math operations take 3 picoseconds, and storing data in memory takes 10 picoseconds. +My friend wrote a filter that makes a pixel more awesome, and takes 200 picoseconds to run. -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. +How long would my computer take to execute the following code if the input image is +1000px wide by 2000px tall? What if it’s n by m? -https://docs.google.com/document/d/1aF1imJUVahCSJAuN1OEm5lQXwpSFaAmVmAETKMM6PLQ/edit#heading=h.za36ai6n5fth +`Pixel **awesomeFilter(Pixel image[][], int width, int height) { +for (int i = 0; i < width; i++) { +for (int j = 0; j < height; j++) { +[image[i][j] makeMoreAwesome]; +} +} +return image; +}` +What is the time complexity of this method, expressed in big O notation? Assume the image is square, and both dimensions are ‘n’. -1) +My friend sends me an improved version of his algorithm, makeEvenMoreAwesome, that takes +into account the pixels around the image. He says it’s O(n^2) in the amount of pixels +in the image. What is the new time complexity of the method? +*/ + +/*: + +#### 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 + +The answer is: 4.3 x 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) + +The answer is: 3n + 215nm + +#### 1c) + +The answer is: O(n^2) + + +#### 1d) + +The answer is: 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 + +The answer is: O(n^4) + +#### 2b) + +int frobnicate(ys, m) { +if (m == 0) { +return 0; +} +return ys[m] + frobnicate(ys, m - 1); +} +frobnicate(xs, n); + +The answer is 0(n); + +Tip: Write down a table with n from 0 to 5 and trace through to find out how many times +frobnicate is called with each value of n. + +#### 2c) + +An algorithm that takes as its input a list of friends of length n, filters out duplicates +using a method similar to our hasDuplicates method, sorts the list using merge sort +(see bigocheatsheet.com), then prints each item to the screen. + +binary sort (hasDuplicates) + merge sort + +O(logn) + O(nlogn) = O(nlogn) + +The answer is: O(nlogn) + + +#### 2d) + +An algorithm that searches the now-sorted list of friends for a specific friend (not including the time it takes to sort). + +O(1) + +*/ + +/*: + +### 3. + +Look at the complexities for some common data structures at bigocheatsheet.com. +Pick a good data structure for each of the following scenarios (there are sometimes +multiple answers): + +#### 3a) -2) +You get a large dataset of points of interest from an API when your app first runs. +You build it once at the beginning, and then have to search it many times while +the user pans around a map. -3) -4) +The answer is: graph or trees -5) -6) +#### 3b) -7) +You get a small dataset of points of interest from an API every time the user +pans the map. You construct the data set many times and only render it once, +then you discard it and do another API search. +The answer is: stack or hash + +Tip: Constructing a dataset of size n means you have to call the data structure’s +insert method n times. So if the data structure has an insert method that takes +O(n2), the time to build it all from scratch is O(n3). + +The answer is: stack or hash table + + +#### 3c) + +You used a linked list for your music app’s playlist feature, but now when people +search their playlist, there’s a noticeable lag before loading results. Your +competitor’s app is buttery smooth when searching, even showing results as you type. +What data structure would allow you to more quickly search without compromising too +much on the speed of inserting and deleting tracks, even in the worst case? + +The answer is: tree + +*/ + +/*: + +### 4. + +#### 4) + +Write an algorithm using one of the methods from exercise 1 (your choice) to +calculate the factorial of a number n. What is the time complexity of your +method in terms of the input value? + +*/ + + +func factorial(num: Int) -> Int{ + + if (num == 0){ + return 1; + } + + else { + return (num * factorial(num - 1)) + } +} + + +/*: + +#### 5) + +Write an Objective C or Swift function to multiply two numbers without using the * operator. +Use the grade school method of multiplying by doing repeated addition. +For instance, 5 * 8 = 5 + 5 + 5 + 5 + 5 + 5 + 5 + 5 = 40. +Find the big O of your function in terms of n and m (the two operands). + + +*/ + +// I didn't account for negative numbers, decimals, or large numbers + +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) + +Look up Russian Peasant Multiplication. It’s a faster way to multiply numbers, +especially on a binary computer (like yours!). Implement a new multiplication +function using this technique and find the big O of your method. If you have +trouble with implementing this, write a flow chart and find the big O based on that. +(But it’s more satisfying to implement it and run it) + +Tip: Run through the method by hand a few times to see how it works and verify to +yourself that it does. It’s a non-intuitive algorithm. This will hopefully also +make the time complexity more clear. + +Write each number at the head of a column. +Double the number in the first column, and halve the number in the second column. +If the number in the second column is odd, divide it by two and drop the remainder. +If the number in the second column is even, cross out that entire row. +Keep doubling, halving, and crossing out until the number in the second column is 1. +Add up the remaining numbers in the first column. The total is the product of your original numbers. +*/ + +func russianPeasantMultiplication(var num1: Int, var num2: Int) -> Int { + + var product = 0 + + if (num1 % 2 != 0){ + product = product + num2 + } + + while (num1 != 1){ + num1 = num1 / 2 + num2 = num2 * 2 + + if (num1 % 2 != 0){ + product = product + num2 + } + } + + return product +} + +/*: + +### 7. + +Using the technique from exercise 4, profile the built in sorting method in objective C +(use an NSMutableArray and google how to sort an array of numbers in objective C). +Graph the result. Use spreadsheet formulas to add graph lines for n, n2, and n*log(n). +(You’ll have to modify the factors to make them fit in the graph window and to be close +to the graph of method execution time). Show that the sort method best fits n * log(n). */ + +var runTime:Double = 0 +var sumTime: Double = 0 +func doThis100TimesToGetAverage(x: Int, arrSize: Int) -> Double { + let numRepeat = x + var count = 0 + print("to repeat \(x)") + func sumItUp(index: Int){ + print("index starts at \(index)") + if (index < x){ + let start = CFAbsoluteTimeGetCurrent() + let arr = Array((0.. - + \ No newline at end of file diff --git a/HWfrom1-10-016(BigO).playground/playground.xcworkspace/contents.xcworkspacedata b/HWfrom1-10-016(BigO).playground/playground.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/HWfrom1-10-016(BigO).playground/timeline.xctimeline b/HWfrom1-10-016(BigO).playground/timeline.xctimeline old mode 100644 new mode 100755 diff --git a/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift b/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift old mode 100644 new mode 100755 index bc0df91..2168191 --- a/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift +++ b/HWfrom1-14-16(Logic+Discrete_Math).playground/Contents.swift @@ -1,6 +1,7 @@ //: Playground - noun: a place where people can play import UIKit +import Foundation var str = "Hello, playground" @@ -17,6 +18,8 @@ Question 2: https://www.hackerrank.com/challenges/handshake Copy and paste your code: + + What is the big O runtime of your code?: Question 3: https://www.hackerrank.com/challenges/connecting-towns @@ -27,3 +30,70 @@ What is the big O runtime of your code?: */ + +func userInput() -> Int { + let input = readLine() + let num = Int(input!) + return num! +} + + +// #1 +let test1 : Int = userInput() // asks for how many tests do you want done +for i in 0.. 1){ + let N = userInput() + total = 1 + for i in 0.. 1){ + let arr +// The Big-O is O(n^2) +// Fundamental of counting principle +// Multiply them altogether +// Multiply the combinations + +} + diff --git a/HWfrom1-14-16(Logic+Discrete_Math).playground/contents.xcplayground b/HWfrom1-14-16(Logic+Discrete_Math).playground/contents.xcplayground old mode 100644 new mode 100755 index 5da2641..89da2d4 --- a/HWfrom1-14-16(Logic+Discrete_Math).playground/contents.xcplayground +++ b/HWfrom1-14-16(Logic+Discrete_Math).playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/HWfrom1-14-16(Logic+Discrete_Math).playground/playground.xcworkspace/contents.xcworkspacedata b/HWfrom1-14-16(Logic+Discrete_Math).playground/playground.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/HWfrom1-14-16(Logic+Discrete_Math).playground/timeline.xctimeline b/HWfrom1-14-16(Logic+Discrete_Math).playground/timeline.xctimeline old mode 100644 new mode 100755 diff --git a/HWfrom1-23-16(Recursion).playground/Contents.swift b/HWfrom1-23-16(Recursion).playground/Contents.swift old mode 100644 new mode 100755 index f7c3b5c..4ad6a85 --- a/HWfrom1-23-16(Recursion).playground/Contents.swift +++ b/HWfrom1-23-16(Recursion).playground/Contents.swift @@ -2,20 +2,5 @@ //THIS IS AN OPTIONAL ASSIGNMENT import UIKit +import Foundation -var str = "Hello, playground" - -//https://docs.google.com/document/d/1KfnTOtPnBrYPFhBRAQPZBXor_mKDQvuJp4zwZbtHkRs/edit#heading=h.16sfqfmanxte - - -//1 - - - - -//2 - - - - -//3 diff --git a/HWfrom1-23-16(Recursion).playground/contents.xcplayground b/HWfrom1-23-16(Recursion).playground/contents.xcplayground old mode 100644 new mode 100755 diff --git a/HWfrom1-23-16(Recursion).playground/playground.xcworkspace/contents.xcworkspacedata b/HWfrom1-23-16(Recursion).playground/playground.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/HWfrom1-23-16(Recursion).playground/timeline.xctimeline b/HWfrom1-23-16(Recursion).playground/timeline.xctimeline old mode 100644 new mode 100755 index bf468af..0068b0a --- a/HWfrom1-23-16(Recursion).playground/timeline.xctimeline +++ b/HWfrom1-23-16(Recursion).playground/timeline.xctimeline @@ -2,5 +2,10 @@ + + diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index e793e5d..904abf4 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ +<<<<<<< HEAD +<<<<<<< HEAD +# unit-4-assignments +Assignments for unit 4 +======= +###Unit 4 Schedule +|Week|Day|Date|Activity|Instructor|Exit Ticket Link| +|---|---|---|---|---|---| +|0|Tuesday|01/05|[How to frame Access Code + Intro to Swift](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-0/2016_01_05.md) (non-technical) |[Intro to Swift](https://docs.google.com/forms/d/1CuY-UFTL3CULwPOWfqFoG4LuEHPAi2iB3ZoJsGTat44/viewform)| +|0|Thursday|01/07|[Intro to data structures / algorithms](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-0/2016_01_07.md)|Cameron| [Data Structures/Algorithms](https://docs.google.com/a/c4q.nyc/forms/d/1FfZbLI9WP5ohJssEeZQk7aQSc5suKmMe6K21xpEENWg/viewform) +|0|Saturday|01/09|[Recap unit 0 in Swift + MVC](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-0/2016_01_09.md)|Linus| [MVC + Swift](https://docs.google.com/forms/d/1ZtOgbNZqI-0KXzmuvebMudQS5EvoOQJ8EZu3J6J8Fuk/viewform) | +|0|Sunday|01/10|[iOS Personal Project + Big O](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-0/2016_01_10.md)|Caleb| [Big O](https://docs.google.com/forms/d/1RbMowGnkMUOXTfbt5CElW4cfwkTlyVKX9K2tT1xm8ZY/viewform) | +|1|Tuesday|01/12|[Technical Pathways with Dion and Job materials (workshop)](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-1/2016_01_12.md) (non-technical) | | x| +|1|Thursday|01/14|[Discrete Math and Logic](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-1/2016_01_14.md)|Cameron| | +|1|Saturday|01/16|[Lists + Sorts](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-1/2016_01_16.md)|Linus| | +|1|Sunday|01/17|[Sorts + Assessment](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-1/2016_01_17.md)|Caleb| | +|2|Tuesday|01/19|[Behavioral interview questions (workshop)](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-2/2016_01_19.md) (non-technical) | |x| +|2|Thursday|01/21|[Intro to Stack + Heap (memory)](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-2/2016_01_21.md)|Cameron| | +|2|Friday|01/22|LinkedIn profile workshop @ LinkedIn (non-technical) | |x| +|2|Saturday|01/23|[Quick Sort + Recursion](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-2/2016_01_23.md)|Linus| | +|2|Sunday|01/24|[Merge Sort + Exercises](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-2/2016_01_24.md)|Caleb| | +|3|Tuesday|01/26|[Entrepreneurship Talk](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-3/2016_01_26.md) (non-technical) | |x| +|3|Thursday|01/28|[Linked Lists, Stacks + Queues](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-3/2016_01_28.md)|Cameron| | +|3|Saturday|01/30|[Sets + Hashmaps](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-3/2016_01_30.md)|Linus| | +|3|Sunday|01/31|[Exercises + Assessment](https://github.com/accesscode-2-2/unit-4/blob/master/lessons/week-3/2016_01_31.md)|Caleb| | + +### Homework + Due Date | Homework | Submission Format | Solution | +|---|---|---|---| +1/09/16, 7:00 pm | [Data Structures Worksheet](http://www.cs.cornell.edu/courses/CS2110/2014sp/L09-Lists/data_structures.pdf) | [Link to Google Form](https://docs.google.com/a/c4q.nyc/forms/d/1qGLpV_eLZv6a-zrS6dHEQqwPv4QbpBSh646XNqa55Ps/viewform) | x +1/11/16, 7:00 pm | [Submit links to updated GitHub, LinkedIn and Resume](https://docs.google.com/document/d/1Y6oAzxDa_K0_0_Mz_S-O5w0LJ5eJUuL4iODAH9Fj2FQ/edit?usp=sharing) | [Link to Google Form](http://goo.gl/forms/KUfBPRHQBr) | x +1/12/16, 10:00 pm | [Passion Project Setup](https://docs.google.com/presentation/d/1Sb6IoD3f842WGugSJZ1s7-4EHgPEdH5RHiT3-H0TI2A/edit#slide=id.gecfcc994a_0_10) | [Link to Google Form](http://goo.gl/forms/qU6GQ8b3pZ) | x +1/14/16, 7:00 pm | [MVC and Unit 0 Swift](https://docs.google.com/document/d/1DQ2aCJ_yUZtazzCfb0PaS81bg61V2ZOSxpABh981xSo/edit) | [Fork this repo. Push to your repo by the deadline](https://github.com/accesscode-2-2/unit-4-assignments) | x | +1/14/16, 7:00 pm | [Big O notation](https://docs.google.com/document/d/1aF1imJUVahCSJAuN1OEm5lQXwpSFaAmVmAETKMM6PLQ/edit#heading=h.za36ai6n5fth) | [Fork this repo. Push to your repo by the deadline](https://github.com/accesscode-2-2/unit-4-assignments) | x +1/16/16, 10:00 am | [Discrete math and logic](https://docs.google.com/document/d/1pqdYlbeoJAVhAR7fT7iuHQ0F-mIH3pbcei-rNX_L5Kw/edit#) | [Pull the hw repo and edit the new playground in your own repo](https://github.com/accesscode-2-2/unit-4-assignments) | x +1/19/16, 7:00 pm | Have a least 2 submission on your blog. Have a detailed README in your passion project repo that outlines the work you will be doing. | Complete this on the blog and repo you linked to on the Google Form | x +1/19/16, 7:00 pm | Revise and resubmit your resume | Upload to the shared [Drive Folder](https://drive.google.com/drive/u/0/folders/0B61otWQVg7ApUFFjWkx6ZE9VOUU) | x +>>>>>>> 4bfda2fa72d440ddfaead3483951409e2176a78f +======= # units-4-5-assignments Assignments for units 4 and 5 +>>>>>>> bd758b001355c38d74c4479f385ea99f853a548d diff --git a/exercises/linked-lists.md b/exercises/linked-lists.md new file mode 100755 index 0000000..370d021 --- /dev/null +++ b/exercises/linked-lists.md @@ -0,0 +1,25 @@ +# Linked Lists + + +*Taken from Cracking the Coding Interview, 6th edition* + +**Remove Dups:** Write code to remove duplicates from an unsorted linked list. + +**Return Kth to Last:** Implement an algorithm to find the kth to last element of a singly linked list + +**Delete Middle Node:** Implement an algorithm to delete a node in the middle of a singly linked list given only access to that node. +> *Example:* +**Input:** the node c from the linked list a -> b -> c -> d -> e +**Result:** nothing is returned, but the new linked list looks like a -> b -> d -> e + +**Partition:** Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. If x is contained within the list, the values of x only need to be after the elements less than x +> *Example:* +**Input:** 3 -> 5 -> 8 -> 5 -> 10 -> 2 -> 1 [partition = 5] +**Output:** 3 -> 1 -> 2 -> 10 -> 5 -> 5 -> 8 + +**Sum Lists:** You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in *reverse* order, such that the 1's digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list. +> *Example:* +**Input:** (7 -> 1 -> 6) + (5 -> 9 -> 2). That is, 617 + 296 +**Output:** 2 -> 1 -> 9 + +**Palindrome:** Implement a function to check if a linked list is a palindrome. diff --git a/exercises/lists.md b/exercises/lists.md new file mode 100755 index 0000000..4012c21 --- /dev/null +++ b/exercises/lists.md @@ -0,0 +1,37 @@ +# Lists + +*Taken from [CodingBat](http://codingbat.com)* + +**First-Last 6** [source](http://codingbat.com/prob/p181624) +Given an array of ints, return True if 6 appears as either the first or last element in the array. The array will be length 1 or more. + +> *Example:* +first_last6([1, 2, 6]) → True +first_last6([6, 1, 2, 3]) → True +first_last6([13, 6, 1, 2, 3]) → False + +**First-Last Same** [source](http://codingbat.com/prob/p179078) +Given an array of ints, return True if the array is length 1 or more, and the first element and the last element are equal. +> *Example:* +same_first_last([1, 2, 3]) → False +same_first_last([1, 2, 3, 1]) → True +same_first_last([1, 2, 1]) → True + +**Rotate Left 3** [source](http://codingbat.com/prob/p148661) +Given an array of ints length 3, return an array with the elements "rotated left" so {1, 2, 3} yields {2, 3, 1}. + +> *Example:* +rotate_left3([1, 2, 3]) → [2, 3, 1] +rotate_left3([5, 11, 9]) → [11, 9, 5] +rotate_left3([7, 0, 0]) → [0, 0, 7] + +**Middle Way** [source](http://codingbat.com/prob/p171011) +Given 2 int arrays, a and b, each length 3, return a new array length 2 containing their middle elements. + +> *Example:* +middle_way([1, 2, 3], [4, 5, 6]) → [2, 5] +middle_way([7, 7, 7], [3, 8, 0]) → [7, 8] +middle_way([5, 2, 9], [1, 4, 5]) → [2, 4] + +You can click through to the [CodingBat website](http://codingbat.com/python/List-1) for a whole bunch of exercises. These exercises are in Python, but you can do them in any language you want. + diff --git a/exercises/logic.md b/exercises/logic.md new file mode 100755 index 0000000..1d571d2 --- /dev/null +++ b/exercises/logic.md @@ -0,0 +1,32 @@ +# Logic + +*Taken from [CodingBat](http://codingbat.com/python/Logic-1)* + +**Cigar Party** [source](http://codingbat.com/prob/p195669) + +When squirrels get together for a party, they like to have cigars. A squirrel party is successful when the number of cigars is between 40 and 60, inclusive. Unless it is the weekend, in which case there is no upper bound on the number of cigars. Return True if the party with the given values is successful, or False otherwise. + +> *Example:* +cigar_party(30, False) → False +cigar_party(50, False) → True +cigar_party(70, True) → True + +**Alarm Clock** [source](http://codingbat.com/prob/p119867) + +Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off". + +> *Example:* +alarm_clock(1, False) → '7:00' +alarm_clock(5, False) → '7:00' +alarm_clock(0, False) → '10:00' + +**Near Ten** [source](http://codingbat.com/prob/p165321) + +Given a non-negative number "num", return True if num is within 2 of a multiple of 10. Note: (a % b) is the remainder of dividing a by b, so (7 % 5) is 2. See also: Introduction to Mod + +> *Example:* +near_ten(12) → True +near_ten(17) → False +near_ten(19) → True + +You can click through to the [CodingBat website](http://codingbat.com/python/Logic-1) for a whole bunch of exercises. These exercises are in Python, but you can do them in any language you want. diff --git a/exercises/recursion.md b/exercises/recursion.md new file mode 100755 index 0000000..5adcee8 --- /dev/null +++ b/exercises/recursion.md @@ -0,0 +1,40 @@ +# Recursion + +*Taken from [CodingBat](http://codingbat.com)* + +**Factorial** [source](http://codingbat.com/prob/p154669) +Given `n` of 1 or more, return the factorial of `n`, which is `n * (n-1) * (n-2) ... 1`. Compute the result recursively (without loops). + +**Bunny Ears** [source](http://codingbat.com/prob/p183649) +We have a number of bunnies and each bunny has two big floppy ears. We want to compute the total number of ears across all the bunnies recursively (without loops or multiplication). + +> *Example:* +bunnyEars(0) → 0 +bunnyEars(1) → 2 +bunnyEars(2) → 4 + +**Bunny Ears 2** [source](http://codingbat.com/prob/p107330) +We have bunnies standing in a line, numbered 1, 2, ... The odd bunnies (1, 3, ..) have the normal 2 ears. The even bunnies (2, 4, ..) we'll say have 3 ears, because they each have a raised foot. Recursively return the number of "ears" in the bunny line 1, 2, ... n (without loops or multiplication). + +> *Example:* +bunnyEars2(0) → 0 +bunnyEars2(1) → 2 +bunnyEars2(2) → 5 + +**Triangle** [source](http://codingbat.com/prob/p194781) +We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows. + +> *Example:* +triangle(0) → 0 +triangle(1) → 1 +triangle(2) → 3 + +**Sum Digits** [source](http://codingbat.com/prob/p163932) +Given a non-negative int n, return the sum of its digits recursively (no loops). Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12). + +> *Example:* +sumDigits(126) → 9 +sumDigits(49) → 13 +sumDigits(12) → 3 + +You can click through to the [CodingBat website](http://codingbat.com/java/Recursion-1) for a whole bunch of exercises. These exercises are in Java, but you can do them in any language you want. diff --git a/lessons/week-0/2016_01_05.md b/lessons/week-0/2016_01_05.md new file mode 100755 index 0000000..e675425 --- /dev/null +++ b/lessons/week-0/2016_01_05.md @@ -0,0 +1,8 @@ +## Objectives +* What is Swift? +* Why Swift vs. Objective-C? +* What are playgrounds and how to use them. + +## Resources +https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html +https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11 diff --git a/lessons/week-0/2016_01_07.md b/lessons/week-0/2016_01_07.md new file mode 100755 index 0000000..2c40e57 --- /dev/null +++ b/lessons/week-0/2016_01_07.md @@ -0,0 +1,106 @@ +## Instructor +Cameron + +## Objectives +* Learn about, compare, and evaluate different data structures +* Understand real-world applications of algorithms and data structures + +## Notes + +### Algorithms + +[Wikipedia](https://en.wikipedia.org/wiki/Algorithm) defines the word _algorithm_ as “a self-contained step-by-step set of operations to be performed”. + +And here's the definition from [_Introduction to Algorithms 3rd Edition_](http://www.amazon.com/dp/0262033844) (via [Medium](https://medium.com/@_marcos_otero/the-real-10-algorithms-that-dominate-our-world-e95fa9f16c04)): +> Informally, an algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. An algorithm is thus a sequence of computational steps that transform the input into the output. + +In other words, an algorithm is a specification for a program. Algorithms operate on [data structures](#data-structures). + +#### Examples + +You've already seen and used some important types of algorithms in your iOS projects: + +* **Sorting** an array + + ```objc + [@[@"c", @"b", @"a"] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] + // -> @[@"a", @"b", @"c"] + ``` +* **Searching** for the index of an object in an array + + ```objc + [@[@"a", @"b", @"c"] indexOfObject:@"b"] + // -> 1 + ``` +* **Inserting** and **accessing** objects in a dictionary (using **hashing**) + + ```objc + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + dict[@"key"] = @"value"; + dict[@"key"] + // -> @"value" + ``` + +Here's a sampling of some of the most important algorithms (or types of algorithms) in use today: + +* [Sorting](https://en.wikipedia.org/wiki/Sorting_algorithm) + * [Sorting Algorithm Visualizations](http://www.sorting-algorithms.com/) +* [Fourier Transform](https://en.wikipedia.org/wiki/Fourier_transform) + * [What is a Fourier transform? What is it used for?](http://www.askamathematician.com/2012/09/q-what-is-a-fourier-transform-what-is-it-used-for/) + * [An Interactive Guide To The Fourier Transform](http://betterexplained.com/articles/an-interactive-guide-to-the-fourier-transform/) +* [Dijkstra’s algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm) + * [Example Networks1: Dijkstra's Algorithm for Shortest Route Problems](http://optlab-server.sce.carleton.ca/POAnimations2007/DijkstrasAlgo.html) +* [RSA](https://en.wikipedia.org/wiki/RSA_(cryptosystem)) + * [Public-Key Encryption by RSA Algorithm](http://logos.cs.uic.edu/340%20notes/rsa.html) +* [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) +* [PageRank](https://en.wikipedia.org/wiki/PageRank) + * [Exploration of the Google PageRank Algorithm](https://bebffd479efdabe8c274b02b19ae9140ad412589.googledrive.com/host/0B2GQktu-wcTiaWw5OFVqT1k3bDA/) +* [Proportional Integral Derivative Algorithm](https://en.wikipedia.org/wiki/PID_controller) + * [PID for Dummies](http://www.csimn.com/CSI_pages/PIDforDummies.html) +* [Data Compression](https://en.wikipedia.org/wiki/Data_compression) + * [Huffman coding](https://en.wikipedia.org/wiki/Huffman_coding) + * [Huffman Coding Tree Visualization](http://algoviz.org/OpenDSA/AV/Binary/huffmanBuildAV.html) +* [Random Number Generation](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) + +#### Resources + +* [The real 10 algorithms that dominate our world](https://medium.com/@_marcos_otero/the-real-10-algorithms-that-dominate-our-world-e95fa9f16c04#.h329od9yw) +* [How Google Search Works](http://www.google.com/intl/en_us/insidesearch/howsearchworks/thestory/) +* [VisuAlgo](http://visualgo.net/) + +### Data Structures + +According to [Wikipedia](https://en.wikipedia.org/wiki/Data_structure), “a data structure is a particular way of organizing data in a computer so that it can be used **efficiently**” (emphasis added). + +Here are some common operations that data structures typically support: + +|Operation|Description| +|---|---| +|Insert|add an element| +|Access|get an element| +|Delete|remove an element| +|Search|find a specific element| +|Sort|reorder elements| + +Depending on the particular structure in question, some of these operations may not apply. For example, it does not make sense to sort a hash table. + +#### Comparison Chart + +Here's a rough comparison of some of the most common data structures. Note the similarities and differences, and consider how a data structure's underlying implementation might affect its performance characteristics. + +|Data Structure|Fast|Slow|Other| +|---|---|---|---| +|Array|insert, access|search, delete|fixed size| +|Array (Sorted)|access, search|insert, delete|"| +|Linked List|insert, delete|search|discontiguous| +|Stack|[LIFO](https://en.wikipedia.org/wiki/LIFO) access|all other access|| +|Queue|[FIFO](https://en.wikipedia.org/wiki/FIFO) access|"|| +|Hash Table|insert, keyed access|search|| +|Binary Tree|insert, delete, search||needs balancing| +|Graph||complex algorithms|best models real-world problems| + +[Source](http://www.idevelopment.info/data/Programming/data_structures/overview/Data_Structures_Algorithms_Introduction.shtml) + +#### Resources + +* [Real-Life Examples of Data Structures (PDF)](http://www.cs.cornell.edu/courses/CS2110/2014sp/L09-Lists/data_structures.pdf) diff --git a/lessons/week-0/2016_01_09.md b/lessons/week-0/2016_01_09.md new file mode 100755 index 0000000..8637862 --- /dev/null +++ b/lessons/week-0/2016_01_09.md @@ -0,0 +1,35 @@ +## Instructor +Linus + +##Standards +* Program in Java, Obj-C, and/or Swift code +* Deliver well-written, robust source code +* Understand application architecture + + + +## Objectives + +####Identify and describe language semantics/syntax (keywords, operators, etc.) +* Optionals + +####Cite common language conventions (naming, formatting, etc.) +* Local vs. external parameter value name +* Don’t use NS objects + +####Create algorithms in Swift to solve interview questions +* Understand the basics of object-oriented programing in Swift + +####MVC +* Explain MVC design: +* Explain what MVC is +* Explain why using MVC is beneficial +* Explain where different logic should be placed in code +* Create/Refactor code in MVC style +* Identify core modules/sections of an app and describe their relationships + +##Exercizes (also homework for this class) +[Algorithm practice](https://docs.google.com/document/d/1DQ2aCJ_yUZtazzCfb0PaS81bg61V2ZOSxpABh981xSo/edit) + +##Class notes +[Lecture slides](https://docs.google.com/presentation/d/1YdD4ZomPFJkzrjGpaGq4CaU7dykHG_WwDEKmNLkuXZk/edit?usp=sharing) diff --git a/lessons/week-0/2016_01_10.md b/lessons/week-0/2016_01_10.md new file mode 100755 index 0000000..0113017 --- /dev/null +++ b/lessons/week-0/2016_01_10.md @@ -0,0 +1,21 @@ +## Instructor +Caleb + +##Standards +Relate fundamental computer science principles + +## Objectives +Developers will be able to: +* Understand the parameters of their independent project (Mike leads this section) +* Understand the derivation of runtime complexity from a given code segment +* Explain a scenario that would run in a given runtime (e.g O(1), O(log n), O(n log n), O(n^2), O(n!) ) +* Given a piece of code, identify its runtime +* Code a solution to a problem and identify the runtime of the solution + +##Exercizes +[Link to Big O exercizes](https://docs.google.com/document/d/1YQWun-aqNaKftjKBAXyG8F5xeU74FEvUYzmhNBuD3u8/edit?usp=sharing) + +##Class Notes +[Lecture Slides](https://docs.google.com/presentation/d/1iMOysVQEV12g8SD3m1YQ4IZWQpSxoeKbQEUJ_Hz27YU/edit?usp=sharing) + +[Passion Project Details](https://docs.google.com/presentation/d/1Sb6IoD3f842WGugSJZ1s7-4EHgPEdH5RHiT3-H0TI2A/edit?usp=sharing) diff --git a/lessons/week-1/2016_01_12.md b/lessons/week-1/2016_01_12.md new file mode 100755 index 0000000..e69de29 diff --git a/lessons/week-1/2016_01_14.md b/lessons/week-1/2016_01_14.md new file mode 100755 index 0000000..c6a793f --- /dev/null +++ b/lessons/week-1/2016_01_14.md @@ -0,0 +1,7 @@ +## Instructor +Cameron + +## Objectives + +## Exercises +[Logic](https://github.com/accesscode-2-2/unit-4/blob/master/exercises/logic.md) diff --git a/lessons/week-1/2016_01_16.md b/lessons/week-1/2016_01_16.md new file mode 100755 index 0000000..968e1ba --- /dev/null +++ b/lessons/week-1/2016_01_16.md @@ -0,0 +1,7 @@ +## Instructor +Linus + +## Objectives + +## Exercises +[Lists](https://github.com/accesscode-2-2/unit-4/blob/master/exercises/lists.md) diff --git a/lessons/week-1/2016_01_17.md b/lessons/week-1/2016_01_17.md new file mode 100755 index 0000000..de07649 --- /dev/null +++ b/lessons/week-1/2016_01_17.md @@ -0,0 +1,4 @@ +## Instructor +Caleb + +## Objectives diff --git a/lessons/week-2/2016_01_19.md b/lessons/week-2/2016_01_19.md new file mode 100755 index 0000000..e69de29 diff --git a/lessons/week-2/2016_01_21.md b/lessons/week-2/2016_01_21.md new file mode 100755 index 0000000..688b842 --- /dev/null +++ b/lessons/week-2/2016_01_21.md @@ -0,0 +1,4 @@ +## Instructor +Cameron + +## Objectives diff --git a/lessons/week-2/2016_01_23.md b/lessons/week-2/2016_01_23.md new file mode 100755 index 0000000..5cbc0f4 --- /dev/null +++ b/lessons/week-2/2016_01_23.md @@ -0,0 +1,7 @@ +## Instructor +Linus + +## Objectives + +## Exercises +[Recursion](https://github.com/accesscode-2-2/unit-4/blob/master/exercises/recursion.md) diff --git a/lessons/week-2/2016_01_24.md b/lessons/week-2/2016_01_24.md new file mode 100755 index 0000000..de07649 --- /dev/null +++ b/lessons/week-2/2016_01_24.md @@ -0,0 +1,4 @@ +## Instructor +Caleb + +## Objectives diff --git a/lessons/week-3/2016_01_26.md b/lessons/week-3/2016_01_26.md new file mode 100755 index 0000000..e69de29 diff --git a/lessons/week-3/2016_01_28.md b/lessons/week-3/2016_01_28.md new file mode 100755 index 0000000..351ed1f --- /dev/null +++ b/lessons/week-3/2016_01_28.md @@ -0,0 +1,8 @@ +## Instructor +Cameron + +## Objectives + +## Exercises + +[**Linked Lists**](https://github.com/accesscode-2-2/unit-4/blob/master/exercises/linked-lists.md) diff --git a/lessons/week-3/2016_01_30.md b/lessons/week-3/2016_01_30.md new file mode 100755 index 0000000..4cd26f5 --- /dev/null +++ b/lessons/week-3/2016_01_30.md @@ -0,0 +1,4 @@ +## Instructor +Linus + +## Objectives diff --git a/lessons/week-3/2016_01_31.md b/lessons/week-3/2016_01_31.md new file mode 100755 index 0000000..de07649 --- /dev/null +++ b/lessons/week-3/2016_01_31.md @@ -0,0 +1,4 @@ +## Instructor +Caleb + +## Objectives