diff --git a/.gitignore b/.gitignore index ddef46d..a1711ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -*.xcodeproj/**/xcuserdata/ +xcuserdata/ .DS_Store diff --git a/2015/2015.xcodeproj/project.pbxproj b/2015/2015.xcodeproj/project.pbxproj new file mode 100644 index 0000000..01e8920 --- /dev/null +++ b/2015/2015.xcodeproj/project.pbxproj @@ -0,0 +1,663 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 55; + objects = { + +/* Begin PBXBuildFile section */ + 260EAFB027004F2300842D82 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260EAFAF27004F2300842D82 /* main.swift */; }; + 260EAFBB2700573200842D82 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260EAFBA2700573200842D82 /* main.swift */; }; + 26780D6326F7733C00C44D54 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26780D6226F7733C00C44D54 /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 260EAFAB27004F2300842D82 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; + 260EAFB62700573200842D82 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; + 26780D5D26F7733C00C44D54 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 260EAFAD27004F2300842D82 /* Day14 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Day14; sourceTree = BUILT_PRODUCTS_DIR; }; + 260EAFAF27004F2300842D82 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + 260EAFB82700573200842D82 /* Day16 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Day16; sourceTree = BUILT_PRODUCTS_DIR; }; + 260EAFBA2700573200842D82 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + 26780D5F26F7733C00C44D54 /* Day13 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Day13; sourceTree = BUILT_PRODUCTS_DIR; }; + 26780D6226F7733C00C44D54 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 260EAFAA27004F2300842D82 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 260EAFB52700573200842D82 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 26780D5C26F7733C00C44D54 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 260EAFAE27004F2300842D82 /* Day14 */ = { + isa = PBXGroup; + children = ( + 260EAFAF27004F2300842D82 /* main.swift */, + ); + path = Day14; + sourceTree = ""; + }; + 260EAFB92700573200842D82 /* Day16 */ = { + isa = PBXGroup; + children = ( + 260EAFBA2700573200842D82 /* main.swift */, + ); + path = Day16; + sourceTree = ""; + }; + 26780D5226F7712800C44D54 = { + isa = PBXGroup; + children = ( + 26780D6126F7733C00C44D54 /* Day13 */, + 260EAFAE27004F2300842D82 /* Day14 */, + 260EAFB92700573200842D82 /* Day16 */, + 26780D6026F7733C00C44D54 /* Products */, + ); + sourceTree = ""; + }; + 26780D6026F7733C00C44D54 /* Products */ = { + isa = PBXGroup; + children = ( + 26780D5F26F7733C00C44D54 /* Day13 */, + 260EAFAD27004F2300842D82 /* Day14 */, + 260EAFB82700573200842D82 /* Day16 */, + ); + name = Products; + sourceTree = ""; + }; + 26780D6126F7733C00C44D54 /* Day13 */ = { + isa = PBXGroup; + children = ( + 26780D6226F7733C00C44D54 /* main.swift */, + ); + path = Day13; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 260EAFAC27004F2300842D82 /* Day14 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 260EAFB327004F2300842D82 /* Build configuration list for PBXNativeTarget "Day14" */; + buildPhases = ( + 260EAFA927004F2300842D82 /* Sources */, + 260EAFAA27004F2300842D82 /* Frameworks */, + 260EAFAB27004F2300842D82 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Day14; + productName = Day14; + productReference = 260EAFAD27004F2300842D82 /* Day14 */; + productType = "com.apple.product-type.tool"; + }; + 260EAFB72700573200842D82 /* Day16 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 260EAFBC2700573200842D82 /* Build configuration list for PBXNativeTarget "Day16" */; + buildPhases = ( + 260EAFB42700573200842D82 /* Sources */, + 260EAFB52700573200842D82 /* Frameworks */, + 260EAFB62700573200842D82 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Day16; + productName = Day16; + productReference = 260EAFB82700573200842D82 /* Day16 */; + productType = "com.apple.product-type.tool"; + }; + 26780D5E26F7733C00C44D54 /* Day13 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 26780D6426F7733C00C44D54 /* Build configuration list for PBXNativeTarget "Day13" */; + buildPhases = ( + 26780D5B26F7733C00C44D54 /* Sources */, + 26780D5C26F7733C00C44D54 /* Frameworks */, + 26780D5D26F7733C00C44D54 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Day13; + productName = Day13; + productReference = 26780D5F26F7733C00C44D54 /* Day13 */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 26780D5326F7712800C44D54 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1300; + LastUpgradeCheck = 1300; + TargetAttributes = { + 260EAFAC27004F2300842D82 = { + CreatedOnToolsVersion = 13.0; + }; + 260EAFB72700573200842D82 = { + CreatedOnToolsVersion = 13.0; + }; + 26780D5E26F7733C00C44D54 = { + CreatedOnToolsVersion = 13.0; + }; + }; + }; + buildConfigurationList = 26780D5626F7712800C44D54 /* Build configuration list for PBXProject "2015" */; + compatibilityVersion = "Xcode 13.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 26780D5226F7712800C44D54; + productRefGroup = 26780D6026F7733C00C44D54 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 26780D5E26F7733C00C44D54 /* Day13 */, + 260EAFAC27004F2300842D82 /* Day14 */, + 260EAFB72700573200842D82 /* Day16 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 260EAFA927004F2300842D82 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 260EAFB027004F2300842D82 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 260EAFB42700573200842D82 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 260EAFBB2700573200842D82 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 26780D5B26F7733C00C44D54 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 26780D6326F7733C00C44D54 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 260EAFB127004F2300842D82 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_STYLE = Automatic; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + 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 = 11.3; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 260EAFB227004F2300842D82 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_STYLE = Automatic; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + 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 = 11.3; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 260EAFBD2700573200842D82 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_STYLE = Automatic; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + 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 = 11.3; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 260EAFBE2700573200842D82 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_STYLE = Automatic; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + 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 = 11.3; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 26780D5726F7712800C44D54 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Debug; + }; + 26780D5826F7712800C44D54 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + }; + name = Release; + }; + 26780D6526F7733C00C44D54 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_STYLE = Automatic; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + 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 = 11.3; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 26780D6626F7733C00C44D54 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_STYLE = Automatic; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + 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 = 11.3; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 260EAFB327004F2300842D82 /* Build configuration list for PBXNativeTarget "Day14" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 260EAFB127004F2300842D82 /* Debug */, + 260EAFB227004F2300842D82 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 260EAFBC2700573200842D82 /* Build configuration list for PBXNativeTarget "Day16" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 260EAFBD2700573200842D82 /* Debug */, + 260EAFBE2700573200842D82 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 26780D5626F7712800C44D54 /* Build configuration list for PBXProject "2015" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 26780D5726F7712800C44D54 /* Debug */, + 26780D5826F7712800C44D54 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 26780D6426F7733C00C44D54 /* Build configuration list for PBXNativeTarget "Day13" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 26780D6526F7733C00C44D54 /* Debug */, + 26780D6626F7733C00C44D54 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 26780D5326F7712800C44D54 /* Project object */; +} diff --git a/2015/2015.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/2015/2015.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/2015/2015.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/2015.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/2015/2015.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/2015/2015.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/2015/Day1.playground/Contents.o b/2015/Day1.playground/Contents.o new file mode 100644 index 0000000..2735afd Binary files /dev/null and b/2015/Day1.playground/Contents.o differ diff --git a/2015/Day1.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift b/2015/Day1.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift new file mode 100644 index 0000000..69f7d46 --- /dev/null +++ b/2015/Day1.playground/Pages/Untitled Page.xcplaygroundpage/Contents.swift @@ -0,0 +1,26 @@ + +func process(code: String) -> (Int, Int?) { + var current = 0 + var basement: Int? = nil + for (index, char) in code.enumerated() { + if char == "(" { + current += 1 + } else if char == ")" { + current -= 1 + } + if basement == nil, current == -1 { + basement = index + 1 + } + } + return (current, basement) +} + +process(code: "(())").0 == 0 +process(code: "()()").0 == 0 +process(code: ")())())").0 == -3 + +let input = """ +()()(()()()(()()((()((()))((()((((()()((((()))()((((())(((((((()(((((((((()(((())(()()(()((()()(()(())(()((((()((()()()((((())((((((()(()(((()())(()((((()))())(())(()(()()))))))))((((((((((((()())()())())(())))(((()()()((((()(((()(()(()()(()(()()(()(((((((())(())(())())))((()())()((((()()((()))(((()()()())))(())))((((())(((()())(())(()))(()((((()())))())((()(())(((()((((()((()(())())))((()))()()(()(()))))((((((((()())((((()()((((()(()())(((((()(()())()))())(((()))()(()(()(()((((()(())(()))(((((()()(()()()(()(((())())(((()()(()()))(((()()(((())())(()(())())()()(())()()()((()(((()(())((()()((())()))((()()))((()()())((((()(()()(()(((()))()(()))))((()(((()()()))(()(((())()(()((()())(()(()()(()())(())()(((()(()())()((((()((()))))())()))((()()()()(())()())()()()((((()))))(()(((()()(((((((())()))()((((()((())()(()())(())()))(()(()())(((((((())))(((()))())))))()))())((())(()()((())()())()))))()((()()())(())((())((((()())())()()()(((()))())))()()))())(()()()(()((((((()()))())()))()(((()(((())((((()()()(()))())()()))))())()))())((())()())(((((())())((())())))(((())(((())(((((()(((((())(()(()())())(()(())(()))(()((((()))())()))))())))((()(()))))())))(((((())()))())()))))()))))(((()))()))))((()))((()((()(()(())()())))(()()()(())()))()((((())))))))(())(()((()()))(()))(()))(()((()))))))()()((((()()))()())()))))))()()()))(()((())(()))((()()()())()(((()((((())())))()((((()(()))))))())))()()())()))(()))))(()())()))))))((())))))))())()))()((())())))(()((()))()))(())))))(()))()())()()))((()(()))()()()()))))())()()))())(())()()))()))((()))))()()(()())))))()()()))((((()))()))))(()(())))(()())))((())())(()))()))))()())))()())()())))))))))()()))))())))((())((()))))())))(((()())))))))(()))()()))(()))()))))()())))))())((((()())))))))())))()()))))))))()))()))))()))))))(())))))))))())))))))))))))))())())((())))))))))()))((())))()))))))))())()(()))))))())))))()()()())()(()()()(()())(()))()()()(()())))())())))()))))())))))))()()()()())(())())()())()))))(()()()()()))))()))())())))((()())()())))()))()))))(()())))()))))))))(((()))()()))))))))))))))))))))(()))(()((()))())))())(()))(()(()(())))))()(()))()))()()))))))))))))()((()())(())())()(())))))())()())((()()))))(()()))))())()(())()))))))))))))))))))))()))(()(()())))))))()()((()))()))))))((())))()))))))))((()))())()()))())()()))((()))())))))))))))(()())()))(())((()(()()))(()())(())))()())(()(())()()))))()))()(()))))))(()))))))))))(()))())))))))))())))))())))(())))))()))))(())())))))))))()(()))))()())))())(()))()())))))))))))))())()()))))()))))))())))))()))))(())(()()()()((())()))())(()))((())()))())())(())(()()))))()))(())()()((())(())))(())))()))())))))))))()(((((())())))(())()))))(())))((()))()(((((((()))))()()))(())))))()(()))))(()()))()))())))))))(()())()))))))))())))(()))())()))(())()((())())()())())(()(()))))()))))))((()())(())()()(()())))()()))(())(())(()))())))()))(()))()()))((((()))))()))((()()()))))()))()))())))(()))()))))(())))()))())()(()))()())))())))))))())))())))()()))))))(()))())())))()))()()())())))))))))))))())))()))(()()))))())))())()(())))())))))))))))))))))()()())())))))()()()((()(()))()()(())()())()))()))))()()()))))))((()))))))))()(()(()((((((()()((()())))))))))))()))())))))((())())(()))())))())))))())()()())(())))())))()())())(())))))))()()(())))()))())))())())())()))))))))()))(()()()())())())))(())())))))))()()())()))))())))())()(())())))))))()())()))(()()(())())))()(()((()()((()()(((((())(()())()))(())()))(())))(())))))))()))()))((()))()))()))))))))()))))))))((()()())(()))(((()))(())))()))((())(((())))()())))())))))((())))))(())())((((((())())()(()))()(()((()())))((())()(()(()))))(())(()()())(())))())((()(((())())))(((()())())))())()(())())((((()()))))())((()))()()()()(())(((((((()()()((()))())(()())))(())())((((()()(()))))()((())))((())()))()(((()))())))()))((()(()))(())(()((((())((((()()(()()))(((())(()))))((((()(()))(())))))((()))(()))((()(((()(()))(()(()((()(())(()(()(()(()()((()))())(((())(()(()))))(()))()()))(())))(())()(((())(()))()((((()()))))())(()))))((())()((((()(((()))())())(((()))()())((())(())())(())()(())()(()()((((((()()))))()()(((()()))))()())()(((()(()))(()(()())(()(()))))(((((()(((())())))))(((((()((()()((())())((((((()(())(()()((()()()()()()()(()()))()(((()))()))(((((((())(((()((()())()((((())(((()(())))()((()(()()()((())((()())()))()))())))())((((((()))(()(()()()))(()((()(()(()))()((()(((()()()((())(((((())()(()))())())((()(())))(()(()())(())((())())())(((()()()(())))))())(()))))))()))))))())((()()()))((()((((((()))(((()((((()()()(((()))())()(()()(((()((()()()()())()()))()()()(()(())((()))))(()))())))))))()(()()(((((())()(()(((((()((()(()()())(()((((((((()((((((())()((((()()()((()((()((((((()))((())))))))())()))((()(()))()(()()(()((())((()()((((((((((((()())(()()()))((((()((((((())(()))())(()()((()()))()(((((((()((()()((((((()(((())))((())))((((((((()()(((((((())(((((()())(((())((())()((((()(((((((()(()(((()((((((()(((()(((((((((((()()((()()(()))((()()(((()(((())))((((())()(()(((())()(()(((())(((((((((((()))())))((((((())((()()((((()())())((((()()))((())(((((()(()()(()()()((())(()((()()((((()(((((()((()(()((((()())((((((()(((((()()(()(()((((())))(())(())(())((((()(()()((((()((((()()((()((((((())))(((((()))))()))(()((((((((()(((())())(((())))(()(()((())(((()((()()(((((()((()()(((())()(()))(((((((())(()(((((()))((()((()((()))(())())((((()((((())()(()))(((()(((((((((((((((())(((((((((()))(((()(()()()()((((((()((())()((((((((()(())(((((((((((()(()((())()((()()(()(()()((((()()((())(()((()()(()()((((()(((((((())))((((())(())()(((()()((()()((((()((()(((()((())(((()()()((((()((((()()(()(()((((((((())(()(((((())(()())(((((((()())()(()((((()((())(()()())((((()()(((()((((())(())(()()(((((((((()()))()(((())(()(()((((((())(()()())(()))()()(((()(((()((())(()(((((((()(()(()((()(((((()(()((()(()((((((()((((()()((((()(((()((())(()(()((()()((((()()(())()(())(((())(()((((((((()())(((((((((()(())()((((())))()))()()(((((()()((((((())(()()(((()(()(((((((()(()(((((((())(())((((()((()(())))((((()()())(()))((()())((((()(((((()(()(())(()(()()())(((((()(((((()((((()()((((((((()()))(()((((((())((((())()(()(((()()()(((()(()(())(())(((((()(())())((((())(())(()(((()(((((())((((())())((()(((((((()(((())(()(()))(((((((((()((()((()()(()((((())(((()((())((((())(()(((()(((()(()((((()(((())(()(((()(()()(()(()((()()(()())(())())((()(()(((()(((()(((()()(((((((((()(((((((((()()(((()(((()())((((()(()(((()()()((())((((((((((())(()(((()((((()())((((()((()))(((()()()(((((()(((((((())((()())(()((((())((((((((())(()((()((((((((((()()((()((()()))(((()())()())()(((()())()()(()(()(((((((())()))(())()))())()()((())()((()((((()((()((())(((((()((((((()(())))(()))())(((()))((()()(()(((()))((((())()(((()))))()(()(())()(((((())(()(()(())(())()((()()()((((()(())((()())(()(()))(()(()(()()(())()()(()((())()((()))))()))((()(()()()()((()())(()))())()(()(((((((((())())((()((()((((((())()((((())(((())((()(()()()((())(()((())(((()((((()()((()(()(((((())()))()((((((()))((())(((()()))(((())(())()))(((((((())(())())()(())(((((()))()((()))()(()()((()()()()()())((((((( +""" + +process(code: input) diff --git a/2015/Day1.playground/contents.xcplayground b/2015/Day1.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day1.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day1.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day1.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day1.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day10.playground/Contents.swift b/2015/Day10.playground/Contents.swift new file mode 100644 index 0000000..02726d4 --- /dev/null +++ b/2015/Day10.playground/Contents.swift @@ -0,0 +1,23 @@ +func step(_ input: String) -> String { + var position = input.startIndex + var output = "" + while position < input.endIndex { + let next = input[position...].firstIndex(where: { $0 != input[position] }) ?? input.endIndex + + let distance = input.distance(from: position, to: next) + + output += "\(distance)\(input[position])" + + position = next + } + + return output +} + +var current = "1321131112" +for _ in 0..<50 { + current = step(current) +} +current +current.count + diff --git a/2015/Day10.playground/contents.xcplayground b/2015/Day10.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day10.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day10.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day10.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day10.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day11.playground/Contents.swift b/2015/Day11.playground/Contents.swift new file mode 100644 index 0000000..31de034 --- /dev/null +++ b/2015/Day11.playground/Contents.swift @@ -0,0 +1,80 @@ +extension String { + func increment() -> String { + var ascii = map { $0.asciiValue! } + + var carry: UInt8 = 0 + for index in ascii.indices.reversed() { + let next = ascii[index] + 1 + if next > UInt8(ascii: "z") { + carry = 1 + ascii[index] = UInt8(ascii: "a") + } else { + ascii[index] = next + carry = 0 + } + + if carry == 0 { + break + } + } + + if carry != 0 { + ascii.insert(UInt8(ascii: "a") + carry - 1, at: 0) + } + + return String(ascii.map { Character(UnicodeScalar($0)) }) + } + + var isValid: Bool { + containsStraight && + !containsForbidden && + containsTwoPair + } + + var containsForbidden: Bool { + contains { $0 == "i" || $0 == "o" || $0 == "l" } + } + + var containsStraight: Bool { + for i in indices.dropLast(2) { + let next = index(after: i) + let next2 = index(after: next) + + let value = self.unicodeScalars[i].value + let value2 = UnicodeScalar(value + 1) + let value3 = UnicodeScalar(value + 2) + + if self.unicodeScalars[next] == value2 && self.unicodeScalars[next2] == value3 { + return true + } + } + return false + } + + var containsTwoPair: Bool { + var firstPair: Character? = nil + for i in indices.dropLast() { + let next = index(after: i) + + guard self[i] == self[next] else { continue } + + if firstPair == nil { + firstPair = self[i] + } else if firstPair != self[i] { + return true + } + + } + return false + } +} + + +let start = "hxbxwxba" + +var password = start +repeat { + password = password.increment() +} while !password.isValid +password + diff --git a/2015/Day11.playground/contents.xcplayground b/2015/Day11.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day11.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day11.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day11.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day11.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day11.playground/timeline.xctimeline b/2015/Day11.playground/timeline.xctimeline new file mode 100644 index 0000000..bf468af --- /dev/null +++ b/2015/Day11.playground/timeline.xctimeline @@ -0,0 +1,6 @@ + + + + + diff --git a/2015/Day12.playground/Contents.swift b/2015/Day12.playground/Contents.swift new file mode 100644 index 0000000..9006735 --- /dev/null +++ b/2015/Day12.playground/Contents.swift @@ -0,0 +1,25 @@ +import Foundation + +let json = """ +[{"a":{"e":{"e":161,"a":"blue","d":{"e":-14,"a":"red","d":{"c":"yellow","a":[-35,0],"b":"orange","d":{"e":70,"a":"green","d":"blue","j":12,"c":69,"h":"orange","b":92,"g":"yellow","f":"green","i":121}},"c":"blue","h":14,"b":46,"g":62,"f":[179]},"j":{"e":133,"c":"violet","a":"orange","b":"blue","d":"violet"},"c":{"e":151,"a":"violet","d":{"e":"red","c":93,"a":135,"g":{"e":43,"c":"green","a":"orange","b":"green","d":54},"b":69,"d":159,"f":2},"c":"green","h":65,"b":{"c":126,"a":106,"b":190,"d":-40},"g":134,"f":"red"},"h":87,"b":[-3,"yellow",50,120],"g":{"e":[138,83,"red"],"c":["yellow",["red",177,98,"blue",179,"blue","violet",23],108,["green",17,-46,3,99],-43,46,"orange","yellow",{"a":192,"b":39},57],"a":"red","b":195,"d":172},"f":97,"i":160},"a":"orange","d":120,"c":61,"h":"red","b":186,"g":{"e":"orange","a":82,"d":{"a":{"e":"green","c":-5,"a":-13,"b":12,"d":"blue","f":-19}},"c":"blue","h":["violet","violet",82,3,"orange","orange",45,"red",198,[81,"red","green","green","yellow",{"c":"orange","a":"blue","b":193},"blue"]],"b":99,"g":{"a":[64,"orange","blue",98],"b":30},"f":"orange","i":[167]},"f":[{"e":"green","c":168,"a":"red","b":173,"d":"blue"},{"e":"violet","c":90,"a":10,"g":{"a":3,"b":195},"b":"orange","d":{"e":143,"c":-26,"a":136,"g":-28,"b":137,"d":"violet","f":[108,70,19,"blue","violet","orange"]},"f":-11},{"e":188,"a":173,"d":135,"j":148,"c":"orange","h":["orange","yellow",108,"violet","violet","blue",188,"yellow","red"],"b":[145,118,"orange","green","green",17,["red",55,86,-20,"green",118,"violet","green"]],"g":{"e":62,"c":"blue","a":"violet","b":-41,"d":5},"f":"green","i":[33,"orange"]},{"a":"green"},{"a":[87,"violet"],"b":"violet"},{"e":"violet","a":147,"d":"blue","c":["blue",91,"violet","violet","yellow","orange","yellow",-4],"h":"yellow","b":19,"g":{"a":"red"},"f":[-38,"yellow","violet",-10,"orange",29,"violet",52],"i":"red"},54,[-14,-2,{"e":12,"a":"violet","d":"blue","j":"orange","c":180,"h":{"e":186,"a":"green","d":"violet","c":"orange","h":"yellow","b":"yellow","g":"green","f":"violet"},"b":"green","g":{"e":"green","c":103,"a":119,"b":"blue","d":"violet","f":116},"f":22,"i":"yellow"},["violet","blue","blue","violet",44,"orange"],144],"red",[119,"red",[10,15,115,"orange",55,"yellow",85,135,-12,"orange"],61,{"e":"red","c":"yellow","a":34,"b":"blue","d":"orange","f":"yellow"},{"c":{"c":"yellow","a":0,"b":"violet"},"a":"orange","b":"green","d":-37},-21]],"i":{"e":[{"e":123,"a":106,"d":100,"j":"violet","c":164,"h":["red",120,"orange","violet",54],"b":-22,"g":"violet","f":"orange","i":130}],"c":{"e":"blue","a":[[198,82,2,"orange",151],128,"violet",88],"d":72,"c":"blue","h":194,"b":4,"g":149,"f":"violet"},"a":[["blue",27,"green",174],"orange",50,"orange",["orange","violet",154,167],"red","orange",{"c":49,"a":"violet","b":76,"d":{"c":166,"a":"red","b":10,"d":185}},53,"yellow"],"b":"orange","d":101,"f":-1}},"b":{"e":{"e":["blue",92,-20,"red","yellow",129,99,"yellow",38],"a":98,"d":129,"c":-5,"h":"green","b":"violet","g":"blue","f":"yellow","i":"red"},"a":"blue","d":[[20,87,"red",124,-2,"yellow","red",17,"violet","yellow"],{"c":"violet","a":"red","b":161},104,{"e":["blue",[51,47,57,-41,"green",149,-11,"red",103,"orange"],"violet",72,"red",["orange","blue","red"],-8,{"c":"violet","a":68,"b":-43,"d":"green"},"orange"],"a":36,"d":["orange","green","green",106,"green","red","red","red","violet"],"j":{"a":"red","b":144},"c":166,"h":109,"b":[{"a":56,"b":"red"},-41,"blue",36,20,"blue","blue"],"g":188,"f":"yellow","i":-7},[155,["green","green",0,"red","blue"],{"e":144,"c":"green","a":"orange","b":133,"d":10,"f":[91,160,"blue",183,18,43,85,-37]},{"e":"violet","a":-35,"d":57,"c":"violet","h":17,"b":"orange","g":57,"f":"red","i":"blue"},"red","red","green","red",29,{"e":112,"c":["red","blue",68,"red","yellow"],"a":"blue","g":"blue","b":{"a":"red"},"d":162,"f":"green"}],"green",[42,"orange"],[["yellow",183,2,"red",115,"red",-31]]],"j":29,"c":{"e":[{"c":"orange","a":{"e":"orange","c":-47,"a":"blue","b":35,"d":25,"f":"blue"},"b":111,"d":16},-44,-22,179,"yellow",84],"a":{"e":178,"a":["red",183,92],"d":163,"c":105,"h":24,"b":"violet","g":-26,"f":[125,"green","violet"],"i":"red"},"d":[[12,"yellow","blue","green"],144,[114,"orange",92,"blue",["violet",40,"blue"],67,105],["orange",155,"violet",37,-38]],"j":{"a":{"c":["green","yellow",-13,"green","red"],"a":[-27],"b":"violet"},"b":["red",[109,57],181,"blue",193,-32,83,"violet"]},"c":128,"h":21,"b":{"e":"red","a":"red","d":"green","c":["green",{"a":"blue"}],"h":"orange","b":{"e":199,"c":35,"a":126,"b":183,"d":60},"g":"orange","f":"violet","i":105},"g":"yellow","f":133,"i":[{"c":"violet","a":"yellow","b":"orange","d":144},"red","yellow","green",105,72,"red","yellow"]},"h":["violet",[[161,"red","blue",[98,"red","violet"],"orange",51,"violet"],"violet",-6,"orange","yellow",51],{"e":72,"a":[190,"red","blue",-13,90,"blue",-6,"violet",137,61],"d":[126,["red",101,118],13,"blue",-4,"blue",[47,157,77]],"c":"orange","h":176,"b":{"c":[67,"green",59,"green",140,"orange","blue",15,53],"a":162,"b":"orange","d":47},"g":49,"f":"yellow","i":"violet"}],"b":{"e":132,"c":[["blue",142,"violet","green",75,56,"green","green"],"red",185,"orange","violet"],"a":144,"b":"violet","d":{"e":"green","a":"blue","d":"violet","c":["violet","yellow","orange","green",121,"blue",-23],"h":"violet","b":"yellow","g":-34,"f":147,"i":127},"f":-25},"g":"green","f":"blue","i":80}},{"e":[43,[34,"yellow",-1,{"e":[150,95],"a":"red","d":"green","j":{"e":"red","c":"yellow","a":"orange","g":-4,"b":-4,"d":{"e":108,"a":"green","d":"orange","j":70,"c":-1,"h":45,"b":"blue","g":-20,"f":"yellow","i":"yellow"},"f":-19},"c":"red","h":90,"b":-46,"g":96,"f":[44,-43,"green","green"],"i":[124,"orange",30,"blue","green","violet",66,"red","orange",125]}]],"c":{"a":[{"c":108,"a":"green","b":"orange"},"green","yellow"],"b":-11},"a":["red",["violet",132,-33,{"a":[148,-13,"orange",84,"yellow",10,"orange","blue"]},["red",-21,{"c":"green","a":"violet","b":"blue"},-1,"red",110,"yellow",51],["violet",{"a":"orange","b":127},[-14,{"a":"yellow"}],{"a":15}]]],"g":"violet","b":["green","violet"],"d":{"a":"yellow","b":"red"},"f":{"e":"green","c":{"a":"orange","b":"violet"},"a":{"c":102,"a":["red","green",{"e":"yellow","a":-41,"d":101,"j":{"a":"yellow"},"c":"yellow","h":"violet","b":19,"g":"blue","f":"yellow","i":61}],"b":["red","green"]},"g":55,"b":"violet","d":{"a":"orange","b":{"e":{"e":-5,"c":113,"a":"orange","g":"blue","b":"orange","d":35,"f":"violet"},"c":"blue","a":26,"b":150,"d":"blue"}},"f":"red"}},[{"a":[{"e":39,"a":"green","d":[[152,198,"yellow",75,"yellow",191,131,"blue"],[177,27,"blue","red"],51,129,"red",{"a":52},"green"],"c":165,"h":"blue","b":4,"g":[{"c":"yellow","a":"violet","b":15},"red","yellow","blue",52,182,{"a":83,"b":"green"},"blue",167,[103,66,105]],"f":-19,"i":162},"blue","orange",165,[153,"green",115],["orange",0,"green",{"c":"violet","a":"red","b":26,"d":198}],{"e":15,"a":["violet",58,-15,"orange",-3],"d":{"e":113,"c":59,"a":["green",-42,"violet",38,"green",-2],"b":"orange","d":"red"},"c":["green",156,"green","yellow",79,"red",126,64,"orange"],"h":"blue","b":"red","g":["orange",43,"red","yellow",{"e":"blue","a":47,"d":"red","c":"violet","h":44,"b":-15,"g":60,"f":"violet","i":-38},"orange",130,34],"f":-49,"i":"yellow"}],"b":[142,"green",[{"c":"yellow","a":181,"b":"yellow"},"blue"],{"a":[["red",35,"green","red",0,"yellow"]],"b":"yellow"},-20]},{"e":88,"a":{"e":"yellow","c":"blue","a":171,"b":{"c":[{"e":"orange","a":"orange","d":"green","c":"green","h":-13,"b":28,"g":70,"f":-30,"i":63}],"a":"green","b":"orange","d":23},"d":"red"},"d":19,"c":"violet","h":[[105,{"e":"orange","a":["red","violet",138,"blue"],"d":21,"j":-20,"c":-26,"h":143,"b":26,"g":119,"f":179,"i":"orange"},"green",["red",48,171,"blue"],"blue","yellow",{"a":"yellow","b":132}],"yellow",{"c":92,"a":{"c":-23,"a":"yellow","b":"violet"},"b":"green","d":[52,124,"violet",{"e":-19,"c":"yellow","a":181,"b":-23,"d":-7},"yellow",139,136]},117,{"e":145,"c":"blue","a":175,"b":42,"d":193}],"b":"yellow","g":[-16,-43,{"a":146,"b":[115,199,"red","violet",150]},{"a":{"c":-14,"a":129,"b":"yellow"}},64,[86,1,109,"orange",[{"e":"blue","c":"blue","a":"violet","b":"orange","d":"yellow"},149,30,"blue",112,{"e":140,"c":"green","a":139,"b":"orange","d":-8},-13,25,111],[127,183,"violet",81,"yellow",192,"blue",{"a":"blue"},"violet",105],71,"violet",18,{"c":37,"a":["red","blue"],"b":184,"d":121}],"green",["yellow",{"e":59,"c":33,"a":154,"g":97,"b":113,"d":"orange","f":23},"yellow",125,"yellow",85,99],34,{"c":100,"a":{"e":"green","a":19,"d":-2,"c":114,"h":72,"b":144,"g":96,"f":85,"i":125},"b":"green","d":-18}],"f":[[73,"blue",132,["yellow","blue","orange","blue",146,15,"orange","orange",{"e":138,"a":"violet","d":194,"c":104,"h":-4,"b":122,"g":-32,"f":"yellow"},-28]],{"e":"red","c":-6,"a":18,"g":-31,"b":44,"d":{"a":117,"b":-37},"f":{"a":"yellow"}},"orange",122,{"e":{"e":-31,"a":"yellow","d":78,"c":118,"h":"green","b":{"a":"violet","b":166},"g":167,"f":126,"i":137},"a":"yellow","d":{"c":152,"a":"blue","b":"green"},"c":"yellow","h":[14,"green",39,171,"red",46,137,-13],"b":"red","g":{"e":"green","c":136,"a":"violet","b":76,"d":"red","f":148},"f":86},-9,["green",156,119,["red",66,198,["orange",-1,34],"yellow",["violet",52,85,-5,"red"],96,43,"violet"],"red",32,95,{"e":119,"a":"blue","d":-8,"c":126,"h":17,"b":"blue","g":178,"f":"violet"},73]],"i":{"e":57,"a":"green","d":195,"c":"violet","h":23,"b":[{"c":"violet","a":122,"b":[64,"violet","green",11,"red",-18,"orange","green","yellow","orange"]},"orange","red",{"e":"violet","a":147,"d":"green","j":-34,"c":{"e":-24,"a":51,"d":"violet","c":"orange","h":121,"b":"blue","g":104,"f":152,"i":99},"h":62,"b":"yellow","g":37,"f":"orange","i":178}],"g":"yellow","f":"violet","i":112}},"violet","violet",{"a":192,"b":"yellow"},["red",["green",165],{"a":"red"},[["green","blue","red","violet",82,"violet","violet",61,86],["violet","green",[187,119,"yellow","orange",17,173],"orange",{"e":"yellow","a":193,"d":87,"c":-1,"h":-1,"b":"red","g":"green","f":"orange"},133,{"e":165,"a":["green",68,-24,"blue"],"d":129,"c":"yellow","h":52,"b":173,"g":"green","f":145},51],141,129],{"c":"red","a":14,"b":"violet","d":{"e":25,"a":118,"d":"orange","c":{"e":6,"c":169,"a":"violet","b":"orange","d":"violet"},"h":29,"b":{"e":"blue","c":"violet","a":["red",176,79,74,"violet","yellow",67,"violet","blue"],"b":"violet","d":"yellow"},"g":34,"f":[47,"green","violet","blue"]}},{"e":"blue","c":{"c":23,"a":"violet","b":16,"d":{"e":-27,"c":"orange","a":{"e":48,"a":56,"d":"yellow","c":173,"h":"violet","b":98,"g":147,"f":"green","i":69},"b":137,"d":[171,"green","orange",1,-22,17,"red","orange","green",-33],"f":"red"}},"a":[{"c":"blue","a":"red","b":-30},"red",{"e":"blue","c":154,"a":"green","b":"blue","d":"red","f":{"e":"blue","c":59,"a":"orange","g":125,"b":84,"d":"green","f":50}},[91,{"e":-20,"c":"red","a":"orange","b":-13,"d":46},79,173,["orange","blue","orange","yellow","red","violet",107,103,32]]],"b":[193,["orange",{"a":6,"b":"violet"},"violet",82,-24,"green"],197],"d":25,"f":-2},{"e":167,"a":-45,"d":"violet","c":55,"h":"red","b":"red","g":"blue","f":21,"i":{"e":198,"c":[{"c":"yellow","a":"green","b":55,"d":"violet"},[44,13,0],{"e":"red","a":197,"d":"violet","c":69,"h":80,"b":92,"g":11,"f":158,"i":130},"red"],"a":"violet","b":"red","d":"yellow"}},[{"e":88,"a":[["green",199,176,-23],{"e":128,"a":185,"d":"yellow","c":142,"h":"blue","b":"red","g":148,"f":124,"i":"violet"},15,"violet","violet",1],"d":"orange","c":"blue","h":-31,"b":[{"e":"violet","c":90,"a":"red","b":24,"d":177},190,65,-14],"g":146,"f":140,"i":126},"green",["yellow",-11,158,11,{"e":"green","c":"red","a":"red","b":{"a":168},"d":7},"orange",107,"green","red"]],167,[["green",{"e":37,"a":"blue","d":"blue","c":-48,"h":"red","b":179,"g":"blue","f":"orange"},{"c":"yellow","a":116,"b":196,"d":97},{"e":"violet","c":{"e":"green","a":"orange","d":107,"c":144,"h":"violet","b":4,"g":98,"f":147,"i":"blue"},"a":"violet","b":"orange","d":["orange",-40,"violet","violet",64],"f":191},["blue","blue"],178,"violet",["violet"]],"violet",49,"green","blue","violet",{"e":"orange","c":61,"a":"orange","b":"green","d":125,"f":["red","yellow","orange",["orange","yellow",-41,27,"violet","orange","blue"],"violet",9,"green","red"]}]],{"e":194,"a":{"e":138,"a":"violet","d":112,"c":[[184,"green","red","violet","blue","red",{"e":"yellow","c":"orange","a":-16,"g":"orange","b":115,"d":"red","f":-6}],149],"h":[-20,["yellow",50,"yellow",20,"red"],"green","blue",-38,128],"b":{"e":["orange",[160],{"e":193,"c":-18,"a":118,"g":"violet","b":"violet","d":"orange","f":"yellow"},183],"c":"red","a":"red","b":{"e":"yellow","a":"yellow","d":99,"c":-13,"h":166,"b":{"e":20,"c":183,"a":"red","b":77,"d":61},"g":-31,"f":"violet","i":"violet"},"d":"orange","f":49},"g":"green","f":166,"i":"red"},"d":{"e":[[-30,"green",-33,"blue"],-38,"red",167,"yellow",["orange",[53,145,67,109,156],"green",189,{"e":"red","c":"red","a":"orange","b":116,"d":"red","f":"violet"},-24,"orange","yellow","violet","violet"],{"e":"red","c":"violet","a":"red","b":76,"d":"blue","f":"orange"},[45,10,"green",168,-9,"violet"]],"c":{"c":[93,-6,109,[12,"orange","red","blue"],"violet"],"a":{"e":-35,"c":{"e":36,"c":-10,"a":105,"b":31,"d":"green"},"a":"green","b":40,"d":"yellow"},"b":["violet",{"e":"violet","a":"blue","d":"blue","c":75,"h":"yellow","b":"orange","g":23,"f":"violet"},187],"d":48},"a":172,"b":{"e":"red","a":"blue","d":[7,"yellow","yellow","red",-2],"c":"blue","h":"blue","b":167,"g":"violet","f":{"a":"yellow"}},"d":"green","f":"orange"},"c":{"e":["violet",{"c":"yellow","a":"violet","b":140,"d":102},62,"yellow",111,69,[84]],"a":114,"d":"violet","c":13,"h":"violet","b":"green","g":99,"f":{"e":"blue","a":"green","d":"blue","j":[-21,"blue","red",88,174,"orange",-1],"c":"yellow","h":[[68,119,152,"yellow"],132,"green","violet","violet",8,{"e":61,"c":1,"a":70,"b":"yellow","d":"blue","f":"violet"}],"b":48,"g":-39,"f":[3,142,"green","blue","violet","orange","orange","yellow","blue",114],"i":["blue","green",82,19,91,18]}},"h":-24,"b":137,"g":153,"f":0,"i":"orange"},{"e":45,"a":{"e":[[62,25,"orange",189,"orange",38,"orange"]],"c":119,"a":100,"b":["red",{"a":"green","b":[-36,"green","red","orange","violet",157,"blue","green",42]},"violet"],"d":[{"c":{"a":24,"b":77},"a":135,"b":8,"d":{"e":185,"a":"violet","d":138,"j":"green","c":-16,"h":6,"b":149,"g":23,"f":"violet","i":"blue"}}],"f":{"e":192,"c":"yellow","a":[-36,"blue",-27],"b":["green",-17,81],"d":"yellow","f":141}},"d":23,"j":{"a":[86,"blue",-22,"orange",123,56,[131,156,58,"violet","green",{"e":27,"a":56,"d":"yellow","c":35,"h":"green","b":84,"g":141,"f":65}],{"a":-17,"b":192},137]},"c":[47,{"e":{"e":95,"a":{"e":182,"a":177,"d":"blue","c":174,"h":-11,"b":"red","g":"yellow","f":"violet","i":39},"d":80,"c":"orange","h":"violet","b":112,"g":-19,"f":"green"},"c":{"c":"violet","a":-18,"b":"green","d":["red",16,-37,"blue","yellow",21,"blue"]},"a":-5,"b":106,"d":31,"f":146},46,-49,{"c":"orange","a":-20,"b":-9},["orange",{"e":["blue","blue",155,"orange","red"],"a":"violet","d":"orange","j":-33,"c":"green","h":"violet","b":"orange","g":"violet","f":173,"i":[-1,"yellow",194,"green",-31,"green"]},{"a":42,"b":{"e":"blue","a":"green","d":"yellow","j":"violet","c":121,"h":102,"b":"orange","g":-27,"f":137,"i":-23}},{"e":{"c":-25,"a":"red","b":129},"c":145,"a":34,"b":108,"d":"red"},"yellow","red","yellow",131,164,6],"yellow",{"a":["orange"],"b":31}],"h":{"e":{"e":"orange","a":"orange","d":{"c":"violet","a":{"e":"blue","a":127,"d":"blue","c":"green","h":"violet","b":88,"g":-40,"f":"yellow","i":"red"},"b":"violet"},"c":["red",{"e":"yellow","a":160,"d":"yellow","j":"blue","c":"orange","h":25,"b":41,"g":44,"f":"yellow","i":106},["yellow",197,21,115,"blue","green",144,38,-24,"blue"],"blue","blue","yellow",148],"h":"red","b":[65,41,{"a":177,"b":118},-42,{"e":13,"c":"orange","a":"violet","g":104,"b":32,"d":"blue","f":"orange"},119,"blue",-44],"g":"violet","f":87,"i":58},"a":128,"d":"green","j":"green","c":[{"a":{"e":"red","c":-24,"a":"yellow","b":"orange","d":"red","f":15}},"violet","green",165,"yellow",{"e":109,"a":101,"d":98,"c":"orange","h":"red","b":"yellow","g":"red","f":78},[166,"green","blue",-20,[33],"red",-9,"yellow","orange",112],"blue"],"h":[{"c":{"e":"yellow","c":144,"a":86,"b":"orange","d":"yellow","f":176},"a":128,"b":"violet","d":{"a":150}},71,{"e":{"a":47},"a":105,"d":45,"c":"green","h":"green","b":112,"g":"red","f":["yellow",196,170,49,"green","red"],"i":91},"blue","blue","green"],"b":{"e":["blue",-40,{"e":-46,"a":-15,"d":"green","c":"red","h":93,"b":18,"g":"yellow","f":-17},"green","violet","green","orange","orange","orange",80],"c":"orange","a":[93,"blue",199,91,"green"],"b":"green","d":{"e":70,"c":"orange","a":"blue","b":-39,"d":198,"f":"blue"}},"g":[57,"violet",81],"f":"violet","i":"violet"},"b":"blue","g":[154,"orange",["yellow",{"e":{"e":-37,"c":-6,"a":"orange","g":"violet","b":"orange","d":"orange","f":77},"c":"green","a":"violet","g":"yellow","b":157,"d":"violet","f":"red"},75,86,"orange"],[{"e":"orange","c":7,"a":["orange",-40,"red",139,"violet"],"b":34,"d":120,"f":"green"},152,119,"orange",{"e":[-5,"orange",107,105,"red","violet",104,136,"violet"],"c":9,"a":199,"b":48,"d":178,"f":152},36],"yellow",89,{"a":155,"b":107},{"a":{"c":13,"a":160,"b":114}},{"a":"yellow"}],"f":["yellow",{"a":"blue","b":157},{"e":"orange","c":[81,-48,"yellow",76,13,"red","red"],"a":{"e":"red","a":"yellow","d":"violet","j":12,"c":"green","h":"green","b":"yellow","g":"yellow","f":76,"i":-44},"b":"blue","d":"green","f":"blue"},{"c":{"a":"orange"},"a":180,"b":"orange","d":133}],"i":{"e":"violet","c":{"e":"orange","c":{"e":[13,"red","yellow","yellow","blue","green","red",156],"c":{"e":"violet","a":"violet","d":"blue","c":102,"h":-7,"b":21,"g":"blue","f":"violet"},"a":129,"b":26,"d":"green"},"a":7,"b":"green","d":"orange"},"a":"red","b":"orange","d":[["yellow",33,178,-31,194,9,126],"orange",27,7,91,[190,-27],[143,{"e":"blue","a":3,"d":5,"c":116,"h":"blue","b":"red","g":"red","f":"violet","i":39},"green",81,[-24,-34,-42,188,63,"orange"],2,172,-44,"yellow",75],{"e":-40,"a":["green","blue","violet",197,-21,"yellow","blue",84,"blue",7],"d":["red","yellow","orange",39,"orange",98,"violet",173],"c":49,"h":38,"b":184,"g":"green","f":-33}]}}],[[[{"e":["violet","blue",53],"a":{"e":77,"c":"orange","a":[166,118,"red",-6,"orange","orange","violet",74,"green"],"b":"red","d":47},"d":"violet","c":92,"h":4,"b":3,"g":{"e":"green","c":"blue","a":"yellow","g":167,"b":"green","d":-31,"f":30},"f":"orange"},{"e":"orange","c":194,"a":"violet","g":-34,"b":43,"d":"yellow","f":"blue"},"yellow",-28],[["green",181,"blue"]],175,"orange",110,198,[185,{"e":183,"c":{"c":29,"a":"blue","b":{"e":45,"a":"yellow","d":"orange","c":"green","h":155,"b":"green","g":-39,"f":"blue","i":"red"},"d":192},"a":"red","g":{"e":{"a":"violet","b":77},"a":-42,"d":57,"j":"orange","c":193,"h":62,"b":"red","g":64,"f":58,"i":"yellow"},"b":[["green",-31,"yellow",141,"yellow","red",111,167,-13,"blue"]],"d":["red",17],"f":"red"},"green",[{"e":22,"c":"orange","a":{"a":"red","b":"violet"},"b":"violet","d":{"a":167,"b":"blue"},"f":56},{"a":{"e":26,"c":145,"a":"violet","g":6,"b":13,"d":"green","f":"yellow"},"b":-41},"yellow",[[120,"red",187,124,"red","green"],"violet","red"],["yellow","violet",34],"yellow","red",71],{"c":["red","green",82,"yellow"],"a":[146,87,"green","orange",168,"yellow"],"b":{"a":["violet"]}},117,"orange",39,144],["violet",{"e":131,"a":-28,"d":["red","green","blue","blue","violet",-15,"violet"],"j":-42,"c":"orange","h":47,"b":"green","g":"yellow","f":[99,140,138],"i":"blue"},{"e":"blue","a":65,"d":"red","c":185,"h":8,"b":["orange",153,{"c":"orange","a":-40,"b":"violet"},"blue","orange",93,175],"g":-27,"f":"yellow","i":-47},48,{"c":83,"a":["blue",184,"orange","blue",{"a":167,"b":"yellow"},"violet","yellow"],"b":-27}],[[12,22,-15,"yellow",34],28,{"e":121,"c":170,"a":"red","g":{"e":13,"a":"yellow","d":44,"j":{"c":198,"a":"violet","b":176},"c":23,"h":-3,"b":"green","g":"blue","f":"violet","i":165},"b":"blue","d":64,"f":189},"yellow",-19,{"e":-49,"c":123,"a":-6,"g":"green","b":[190,"red","orange",68,98,"yellow","orange","red",{"c":68,"a":"red","b":"red"},"violet"],"d":-27,"f":"orange"},17,{"a":[105,127,{"e":-1,"a":138,"d":173,"j":"green","c":"blue","h":80,"b":"yellow","g":176,"f":"green","i":"green"},139,-41,"blue",10]},"orange"]],[[[{"e":"green","a":"blue","d":"orange","j":"blue","c":"yellow","h":"yellow","b":{"c":199,"a":"violet","b":-19},"g":"yellow","f":"red","i":"violet"},["orange"],[{"e":-20,"a":72,"d":"violet","c":"green","h":"yellow","b":20,"g":62,"f":-46},["yellow",48,44,"yellow","orange",-19,"green","red",10],{"c":0,"a":"blue","b":"green"},71,168,-27,"red"],{"e":"violet","a":{"a":"violet"},"d":-32,"c":"orange","h":"orange","b":"yellow","g":144,"f":131,"i":"orange"},"orange","violet","yellow","red"],151,[18,[{"a":"green"}],"orange","red","blue"]],{"c":91,"a":-17,"b":47,"d":46}],[["orange","green",[132],[4,156,186,{"e":148,"a":"green","d":"red","c":14,"h":34,"b":98,"g":141,"f":197,"i":"blue"},"red"],["yellow",["red","violet",-8,{"e":"orange","a":86,"d":"green","c":-49,"h":"green","b":"orange","g":107,"f":"green","i":174},101,57,"red","red",{"c":"orange","a":185,"b":84,"d":"blue"}],92,"orange","green","green",{"e":[-17,"blue","violet"],"c":["blue",80,"red"],"a":134,"g":192,"b":"green","d":"violet","f":51}],{"e":[122,"yellow","green","orange"],"a":"blue","d":113,"c":"yellow","h":"yellow","b":["violet","violet",199,71,128,["yellow","green","violet","blue",-41,"green","violet","yellow","yellow"],["yellow",190,"green","green","orange","green",-30,61]],"g":{"a":136,"b":"red"},"f":[135,"violet",60,["yellow",16,"blue"],131,"yellow",{"e":"orange","c":"violet","a":62,"b":190,"d":109},"blue",68,{"a":58,"b":-31}]},"yellow",-17,"violet","red"],44,[-39,"orange",{"e":70,"c":199,"a":73,"g":12,"b":"orange","d":6,"f":"green"},["blue","red",58,{"e":51,"c":80,"a":[46,26,"violet",64,"violet"],"b":"red","d":"red"},{"a":"yellow","b":"blue"}],196,{"a":"orange","b":{"c":"yellow","a":66,"b":161}}],157,[-25,["red",31],96,"yellow",[{"a":"green","b":9},"yellow",147,"yellow","green","orange",[-4,"green",66,152,157,["violet","violet",45,199,36,"violet",125,25]],50,["green",34,"orange",-37,33,179]],"green",{"e":"violet","a":["red",{"e":40,"a":"green","d":-24,"c":174,"h":"violet","b":"red","g":180,"f":63},"red","red",{"a":-36},178,-19,"violet",["green","red",24,"red"],"violet"],"d":{"e":24,"c":9,"a":7,"g":-41,"b":44,"d":"red","f":"violet"},"c":"violet","h":"yellow","b":["red"],"g":"yellow","f":-1,"i":["blue",53,"violet","red",87,"blue",{"e":-20,"a":130,"d":"red","c":"blue","h":58,"b":"blue","g":"blue","f":"blue","i":"yellow"},"orange","green"]},["red","green","green",-23,-6,75,"blue",{"e":112,"a":"green","d":129,"c":"yellow","h":"green","b":"yellow","g":-16,"f":194,"i":{"a":"violet","b":114}},"blue",[87,{"a":"violet"},10,65,70,"yellow",104,78,-41]],{"e":"violet","a":[[180,108],"orange","green","yellow",119,52],"d":113,"j":"red","c":[91,"green","red",41,"red",41],"h":"yellow","b":{"e":"orange","c":188,"a":77,"g":"yellow","b":"blue","d":-46,"f":"blue"},"g":"yellow","f":"yellow","i":{"e":{"e":"yellow","c":112,"a":"red","b":-36,"d":10,"f":"blue"},"a":{"a":172},"d":["green",92,87,65,123],"c":"blue","h":{"c":152,"a":"green","b":107,"d":-47},"b":"violet","g":25,"f":65,"i":"blue"}},"violet"],[["orange",{"e":"yellow","c":"orange","a":"orange","b":128,"d":145},"blue",-3,"green",108,"yellow",153],{"e":"red","c":50,"a":[90,"green",34,91,{"c":"orange","a":"red","b":197,"d":"red"}],"b":{"e":[54,"yellow","yellow"],"a":{"e":"orange","c":"yellow","a":"red","g":59,"b":"orange","d":161,"f":15},"d":"green","c":"orange","h":"green","b":25,"g":"green","f":"green","i":[191,95,-39]},"d":11},"yellow",39,"green","blue"],{"e":[[-45,[77,"yellow",-2,149,"blue",37,114],"violet",53,"green","violet",86,"green",2],135,-36,193,{"e":177,"a":33,"d":23,"j":"orange","c":-49,"h":79,"b":"violet","g":2,"f":"orange","i":-11},{"c":35,"a":"green","b":"blue"},"red",71,"violet","yellow"],"a":{"c":[100,"red",-32,"green","red","red",106,"red"],"a":"violet","b":-37,"d":{"e":145,"a":22,"d":[-45,85,-25,141],"j":"yellow","c":150,"h":[-4,"violet","green","violet",197,26,52,13,"blue",195],"b":165,"g":79,"f":-2,"i":"yellow"}},"d":[174,182,4,111,"violet",[25,"violet","yellow","red",107,124,114,"violet"],["red",57,-26,"green",131,25,"blue",["green","blue",47,-9,91,"yellow","red",-29,"red"]]],"c":[49,"violet",-24,56,99,127,26],"h":{"e":30,"a":10,"d":"violet","c":{"e":"blue","c":192,"a":86,"g":"blue","b":111,"d":[198,"green"],"f":-42},"h":-9,"b":["violet",{"e":29,"a":"blue","d":49,"j":109,"c":99,"h":-9,"b":"violet","g":"orange","f":120,"i":"orange"},["green",-7,"green"],"blue",129,"green","violet",{"e":-7,"a":"blue","d":130,"c":"green","h":126,"b":158,"g":"blue","f":132,"i":"blue"},191,"orange"],"g":183,"f":"yellow"},"b":"orange","g":[-7,"blue",{"e":"orange","a":"yellow","d":"violet","j":139,"c":33,"h":"blue","b":"red","g":-20,"f":3,"i":151},"blue",136,"orange",160],"f":[128]}],[["blue",185,57,82,{"e":"yellow","a":"red","d":"violet","c":5,"h":"yellow","b":16,"g":11,"f":-27}],[["orange",38,{"c":"green","a":"blue","b":[177,"blue","violet",-41,"orange",41,67,106]},"green","blue","red"],"violet",["green",-13,"orange",6,{"e":"red","a":116,"d":"orange","c":100,"h":"violet","b":"yellow","g":"red","f":"red","i":"red"},{"e":36,"a":"blue","d":"blue","j":135,"c":194,"h":-27,"b":["green",186,"green","violet","violet",197,32],"g":["blue"],"f":"violet","i":101},-47,"violet",30],[11,"orange",[-11,{"a":"green","b":-32},-21,133],{"a":32}],"orange",-49,102,136,"blue",125],-1,{"e":"orange","a":{"e":{"c":"violet","a":"green","b":13,"d":"blue"},"a":[{"e":"red","c":"orange","a":67,"g":"blue","b":"red","d":103,"f":176},7,5,176],"d":["orange",[-12,"orange","orange","yellow",165,152],["blue",38,"yellow","blue"],"violet",157,"orange"],"c":153,"h":"yellow","b":"green","g":["blue",[11,"red","yellow","green",16,89,"yellow"],"violet",180,120],"f":-21,"i":166},"d":["yellow",{"e":"violet","c":"green","a":"red","b":156,"d":"blue","f":{"e":38,"a":"orange","d":109,"c":"orange","h":93,"b":"green","g":-19,"f":-4}},{"e":88,"c":81,"a":50,"b":184,"d":"orange"},{"a":"green"},"red",[31,["blue",37],"violet",-5,16,"red",-43],"orange",32,[-10,72,16,138,"blue","green","violet"],"green"],"c":"violet","h":{"e":49,"c":-25,"a":"violet","b":42,"d":["red",-5,65,"green",-47,146,{"e":"red","c":167,"a":113,"b":169,"d":"red"},-19,"blue"],"f":"blue"},"b":{"a":89},"g":{"e":-42,"c":"green","a":-27,"b":{"e":"orange","a":"blue","d":"violet","j":"green","c":-8,"h":112,"b":-45,"g":-27,"f":"green","i":["violet","yellow","blue","violet",13,"blue",21]},"d":["orange",113,152,115,"red",112,-11,-5,{"e":"blue","c":"orange","a":158,"b":57,"d":"violet"}],"f":42},"f":[18,"yellow","red"],"i":-37}],{"c":[-7,"orange","green","green"],"a":{"a":"blue"},"b":{"e":"orange","a":114,"d":{"c":{"c":45,"a":26,"b":-4},"a":111,"b":["yellow",["red",196,"blue","yellow","orange","orange"],"red",-39,"orange","red","blue",{"e":"red","c":"red","a":"violet","b":"green","d":-13,"f":144},18],"d":22},"c":["green",{"c":"orange","a":20,"b":"yellow","d":120},98,107,"green","orange",181,[69,-30,{"e":"red","a":"blue","d":"orange","c":42,"h":136,"b":"blue","g":24,"f":35,"i":"red"},["violet","blue",77,152,"violet","red","orange"],185,[87,59],178,"yellow"],"violet"],"h":172,"b":{"c":"orange","a":{"e":161,"c":52,"a":33,"b":"violet","d":169,"f":122},"b":{"e":"yellow","a":-12,"d":"yellow","c":43,"h":-30,"b":"blue","g":94,"f":"yellow"},"d":{"e":0,"a":37,"d":"green","c":-30,"h":101,"b":111,"g":"orange","f":195}},"g":{"a":138,"b":"yellow"},"f":[160]},"d":"violet"},[{"c":{"e":{"e":[-30,"green",127],"c":"red","a":"red","b":123,"d":163},"c":"violet","a":[62,"red",101,103,172,"green",{"e":"orange","a":"blue","d":"green","j":23,"c":"red","h":"blue","b":43,"g":"orange","f":"red","i":-31},"violet",159],"b":"orange","d":37,"f":143},"a":"blue","b":136},{"e":74,"a":49,"d":"violet","j":176,"c":{"e":147,"c":50,"a":158,"b":{"e":55,"a":99,"d":"yellow","c":{"e":"red","a":"yellow","d":-14,"j":89,"c":79,"h":185,"b":138,"g":-1,"f":66,"i":"green"},"h":{"a":-9},"b":{"e":-19,"a":"violet","d":"red","c":-5,"h":99,"b":11,"g":"green","f":90},"g":177,"f":146,"i":"green"},"d":190,"f":{"e":"red","c":"yellow","a":"blue","g":"blue","b":135,"d":-49,"f":114}},"h":"yellow","b":88,"g":[{"a":["green","red",36,"violet"]},{"e":[118],"c":"violet","a":-4,"b":"red","d":"blue"},"violet","green",[["green","blue",81,"orange","blue","violet","violet",115,195],19,39,39,31,41,-1],"yellow",{"a":42,"b":149},79],"f":129,"i":173},["violet",{"e":48,"a":81,"d":102,"j":76,"c":182,"h":{"a":43,"b":"violet"},"b":-27,"g":166,"f":["orange",["yellow"],36,"green",[86,"green",2,"yellow",-36],83,"yellow","orange",89],"i":133},[{"a":"violet","b":"violet"},"blue","orange","orange",161,"violet",[196,-14,152,{"a":129},"violet"],181,"red","red"],{"e":"violet","c":40,"a":["orange","violet","yellow","violet","yellow",91,"orange","violet",108],"g":"orange","b":"blue","d":[{"a":"orange"},-28,7,"orange",{"a":"violet"},183],"f":-12},115,-32,"yellow","violet","orange",193],{"e":{"a":147,"b":11},"c":127,"a":79,"b":"yellow","d":-5},{"e":[{"e":1,"a":101,"d":"blue","c":[126,"violet",-24,"green"],"h":"blue","b":149,"g":"orange","f":"violet"},"red","red",{"a":5,"b":"orange"},"red"],"c":{"e":"orange","a":-49,"d":"red","j":-22,"c":{"e":"blue","c":155,"a":-2,"g":"blue","b":{"c":"violet","a":151,"b":"blue","d":"violet"},"d":{"c":55,"a":"blue","b":68,"d":"green"},"f":"green"},"h":"red","b":"red","g":27,"f":[["violet","blue"],"violet",144,111,-24,"blue","red","yellow"],"i":{"a":155,"b":38}},"a":"red","b":1,"d":"yellow","f":{"e":{"c":78,"a":40,"b":"green"},"c":"yellow","a":122,"g":"blue","b":"red","d":{"a":[70,79,65,"green",77,"red",133]},"f":[115,"blue"]}},{"c":42,"a":[{"e":"violet","c":{"e":"violet","a":"blue","d":"yellow","c":"violet","h":-24,"b":11,"g":"green","f":"green","i":"violet"},"a":122,"b":"orange","d":"violet"},[197,"blue",62,-32,127,119,"orange","blue"],121,{"c":198,"a":"orange","b":["red","yellow","yellow"],"d":"red"},-5],"b":{"e":14,"c":-41,"a":[["green",75,"yellow",138,"green","orange",42,188],21,98,109,149],"g":-36,"b":[-34,["orange","green",98,-45],[33,89,"blue","green"],184,"violet","yellow"],"d":["green",["orange",111,"blue","orange","blue","yellow","orange",189,"yellow","blue"],"orange",98,"green"],"f":[-32,{"e":-13,"c":"blue","a":108,"g":106,"b":153,"d":-45,"f":3},"blue",109,"blue"]}},[[[172,{"e":"red","a":"blue","d":71,"j":"green","c":61,"h":"orange","b":133,"g":155,"f":153,"i":169},"red",-6,"red",155],[60,130,80],"blue",["green",63,"green",127,"red"],["yellow",185,{"c":"orange","a":27,"b":"blue"},"yellow","violet",{"c":32,"a":6,"b":-37},-18],"yellow",138,["blue",{"e":94,"c":"blue","a":156,"b":-15,"d":52},101,"orange",61],"blue"],{"e":[62,"blue","red"],"a":138,"d":"red","j":"yellow","c":"blue","h":["green","green",-42,"green"],"b":["red",3,-36,"red","red","violet",{"e":"violet","a":"blue","d":77,"c":"orange","h":"yellow","b":"violet","g":"orange","f":"green","i":"blue"}],"g":[193,"blue","yellow",74,"green",-24,96,7],"f":-9,"i":"blue"},["yellow",[138,100,"orange",62,-30,"blue","green"],"yellow","violet",19]],109,{"e":"violet","a":"blue","d":90,"j":-39,"c":"green","h":[{"a":"green","b":153},91],"b":189,"g":"blue","f":"orange","i":"green"}],{"a":{"c":"green","a":34,"b":["yellow",181,-2,126,"blue","orange","violet"],"d":["red","violet",133,[192,176,16,"blue",3],[96,"blue","red","orange",[-16,"red",119,"yellow","orange","red",149,"red"],"red","violet","violet",-17,"yellow"],["blue"],"blue","green","blue"]},"b":{"a":"green","b":"violet"}},{"e":{"e":170,"c":139,"a":[{"e":-15,"a":78,"d":"violet","j":-1,"c":7,"h":71,"b":[116,-1,-25,-20],"g":"blue","f":"green","i":68},-25,[[125,"orange",134,"orange",35,50,126],-3,[166,"red",33,"red",85],-33,"orange",[198,"violet","red","blue",106,141,-45],-47],77,[["violet",74,"green","yellow",130,"violet"],9],{"e":9,"a":140,"d":111,"c":"yellow","h":"orange","b":"yellow","g":"violet","f":"red"}],"b":{"e":"green","c":167,"a":[16,-5,"green","red","green"],"b":-27,"d":"blue","f":"orange"},"d":{"e":{"c":66,"a":{"e":"red","a":"violet","d":"yellow","j":"red","c":"blue","h":-32,"b":95,"g":"violet","f":31,"i":"red"},"b":"blue","d":"blue"},"a":"red","d":{"c":75,"a":"yellow","b":"green","d":["green",-21,171,"yellow","blue",131,0,-33]},"c":[164,"orange"],"h":"red","b":118,"g":161,"f":"yellow","i":{"e":"violet","a":"green","d":{"e":123,"c":"violet","a":"orange","g":46,"b":-29,"d":"yellow","f":43},"c":-44,"h":"green","b":{"c":"green","a":81,"b":31,"d":"blue"},"g":"yellow","f":3}},"f":"green"},"c":"yellow","a":[["yellow","blue","red",168,69,[-44,"orange"],{"e":"blue","c":"yellow","a":65,"b":"yellow","d":"red","f":"orange"},"green","blue","blue"],{"e":{"c":48,"a":-39,"b":["orange",127,"blue","blue",92,"green"],"d":"red"},"a":-41,"d":"blue","j":"blue","c":134,"h":["violet","red"],"b":-48,"g":13,"f":"blue","i":["red",131,"blue","orange","green","green",161]},{"e":197,"a":-17,"d":-48,"c":"violet","h":177,"b":123,"g":"violet","f":-12,"i":[52,148,"violet","red",128,["blue"]]},[17,-28,{"e":-20,"a":{"a":"violet"},"d":"yellow","c":{"a":"blue","b":"violet"},"h":11,"b":39,"g":{"e":"blue","a":"green","d":"violet","c":"orange","h":"blue","b":132,"g":137,"f":"red"},"f":"blue","i":[187]},{"e":"violet","c":149,"a":"green","g":"red","b":72,"d":[-5],"f":{"c":11,"a":-2,"b":"green"}},-6,["green","yellow","yellow",{"e":"orange","c":"red","a":185,"b":"green","d":"red"}]],4],"g":"orange","b":[{"e":["violet","violet","green",119,-26],"a":"blue","d":"red","c":{"e":-38,"c":"green","a":17,"b":{"a":-31},"d":"yellow"},"h":["red","violet",-13,-41,[197,"violet","orange",150,"violet",156,161,179,70,"red"],143,110,-2,"blue","green"],"b":"green","g":"blue","f":"red"},"orange",{"c":[26,{"c":-21,"a":"green","b":"red"},"blue","orange",-23,"green",179,["orange"],{"e":"orange","c":"blue","a":"green","b":169,"d":"red"},"orange"],"a":"violet","b":"blue","d":175},60,"orange",[-44,{"e":"green","c":"orange","a":-41,"b":"violet","d":[0,"orange","green"]},"blue",["violet",[26,-9,"yellow",101,6,"yellow",161],81,104,"red","red","violet","red",180,60],114],"orange",15,22,"yellow"],"d":[53,"yellow",{"e":{"e":[99],"a":51,"d":["orange","yellow",114],"c":67,"h":{"e":109,"c":"violet","a":"orange","g":"orange","b":"blue","d":"orange","f":-4},"b":-27,"g":[93,"orange"],"f":"blue","i":"red"},"a":"red","d":37,"j":{"c":"red","a":"blue","b":"orange","d":{"a":"violet"}},"c":["green"],"h":"orange","b":[32,{"c":"red","a":"red","b":34},81,-3,{"c":"red","a":133,"b":-47,"d":112},"green","green","orange",{"e":"blue","a":"orange","d":"green","j":45,"c":-16,"h":78,"b":-28,"g":"yellow","f":"blue","i":130},0],"g":116,"f":-5,"i":"red"},"yellow","blue",152],"f":{"c":{"e":116,"c":"orange","a":128,"b":"blue","d":"blue"},"a":2,"b":{"c":101,"a":-48,"b":["yellow",106,179,["orange",97,104,"violet","orange","blue","orange"],{"e":"blue","a":183,"d":"red","c":-8,"h":26,"b":"orange","g":4,"f":"orange"},"violet","green","blue","green"]}}}],[{"e":10,"c":[[{"a":195},"yellow",[89,"orange","blue",[158,"violet",-41,174,135,"red",-21,182,"yellow","green"]],"green",{"e":"orange","a":[159,-6],"d":"yellow","j":"violet","c":"green","h":-23,"b":"orange","g":108,"f":"orange","i":53},["blue"],["blue","blue",[3,"violet","red"],"violet","yellow","violet"],85,92,"yellow"],{"a":"violet","b":188},"violet",{"a":197}],"a":-46,"g":"yellow","b":[54,["yellow","orange","violet",168,197,125,{"e":"blue","c":-24,"a":"orange","g":164,"b":"red","d":148,"f":{"e":48,"c":61,"a":"yellow","g":"blue","b":-46,"d":56,"f":-4}},{"a":["blue",131,6]},{"c":[179],"a":-13,"b":"violet","d":-34},-22],"violet",187],"d":34,"f":"yellow"},197,[{"e":52,"c":96,"a":{"e":59,"c":"orange","a":73,"b":["blue","green"],"d":-22},"b":{"e":["blue",152],"a":123,"d":"green","c":28,"h":-33,"b":-8,"g":"violet","f":167,"i":-29},"d":[[-21,"yellow"],52,"blue","red"]},-21],176,[[[193],53]],[[175,{"e":"red","a":132,"d":113,"c":["yellow"],"h":["red",185,129,57,"violet",135,"green","yellow","blue","green"],"b":"orange","g":-20,"f":{"c":"red","a":"orange","b":{"a":"violet","b":11}},"i":141},28,{"e":-4,"a":{"e":51,"a":171,"d":103,"c":{"e":-9,"a":144,"d":"green","j":"orange","c":"violet","h":126,"b":"yellow","g":60,"f":"violet","i":"orange"},"h":{"e":-40,"c":99,"a":"orange","g":"green","b":"red","d":128,"f":"blue"},"b":"green","g":82,"f":-23},"d":-16,"j":"violet","c":108,"h":140,"b":"yellow","g":"blue","f":84,"i":"orange"},[{"e":"red","c":-31,"a":-23,"g":-11,"b":25,"d":"green","f":"green"},{"e":"blue","c":180,"a":58,"b":-27,"d":60,"f":79},"orange",172],"red"],["orange",{"c":64,"a":109,"b":-14,"d":"red"},{"a":70,"b":"orange"},["violet",17],{"e":"violet","a":[141,"blue",{"a":"red"},[142,"red","violet","violet",-45,58,78,"yellow","orange"],"orange"],"d":{"e":"green","a":"red","d":86,"c":{"e":-44,"a":33,"d":"violet","c":188,"h":"red","b":-36,"g":"blue","f":"yellow"},"h":"red","b":186,"g":166,"f":"red"},"c":20,"h":"red","b":["violet",{"e":"blue","a":187,"d":115,"j":193,"c":119,"h":"yellow","b":"yellow","g":"red","f":74,"i":25},"orange",0,-17,"yellow",-23],"g":199,"f":76}]]]] +""" + +let data = try! JSONSerialization.jsonObject(with: Data(json.utf8), options: []) + +func countNumbers(_ value: Any) -> Int { + if let array = value as? [Any] { + return array.reduce(0) { $0 + countNumbers($1) } + } else if let dict = value as? [String: Any] { + if dict.values.contains(where: { $0 as? String == "red" }) { + return 0 + } + return dict.values.reduce(0) { $0 + countNumbers($1) } + } else if let number = value as? Int { + return number + } else { + return 0 + } +} + +countNumbers(data) + diff --git a/2015/Day12.playground/contents.xcplayground b/2015/Day12.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day12.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day12.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day12.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day12.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day13/main.swift b/2015/Day13/main.swift new file mode 100644 index 0000000..0996df0 --- /dev/null +++ b/2015/Day13/main.swift @@ -0,0 +1,188 @@ +import Foundation + +let input = """ +Alice would lose 2 happiness units by sitting next to Bob. +Alice would lose 62 happiness units by sitting next to Carol. +Alice would gain 65 happiness units by sitting next to David. +Alice would gain 21 happiness units by sitting next to Eric. +Alice would lose 81 happiness units by sitting next to Frank. +Alice would lose 4 happiness units by sitting next to George. +Alice would lose 80 happiness units by sitting next to Mallory. +Bob would gain 93 happiness units by sitting next to Alice. +Bob would gain 19 happiness units by sitting next to Carol. +Bob would gain 5 happiness units by sitting next to David. +Bob would gain 49 happiness units by sitting next to Eric. +Bob would gain 68 happiness units by sitting next to Frank. +Bob would gain 23 happiness units by sitting next to George. +Bob would gain 29 happiness units by sitting next to Mallory. +Carol would lose 54 happiness units by sitting next to Alice. +Carol would lose 70 happiness units by sitting next to Bob. +Carol would lose 37 happiness units by sitting next to David. +Carol would lose 46 happiness units by sitting next to Eric. +Carol would gain 33 happiness units by sitting next to Frank. +Carol would lose 35 happiness units by sitting next to George. +Carol would gain 10 happiness units by sitting next to Mallory. +David would gain 43 happiness units by sitting next to Alice. +David would lose 96 happiness units by sitting next to Bob. +David would lose 53 happiness units by sitting next to Carol. +David would lose 30 happiness units by sitting next to Eric. +David would lose 12 happiness units by sitting next to Frank. +David would gain 75 happiness units by sitting next to George. +David would lose 20 happiness units by sitting next to Mallory. +Eric would gain 8 happiness units by sitting next to Alice. +Eric would lose 89 happiness units by sitting next to Bob. +Eric would lose 69 happiness units by sitting next to Carol. +Eric would lose 34 happiness units by sitting next to David. +Eric would gain 95 happiness units by sitting next to Frank. +Eric would gain 34 happiness units by sitting next to George. +Eric would lose 99 happiness units by sitting next to Mallory. +Frank would lose 97 happiness units by sitting next to Alice. +Frank would gain 6 happiness units by sitting next to Bob. +Frank would lose 9 happiness units by sitting next to Carol. +Frank would gain 56 happiness units by sitting next to David. +Frank would lose 17 happiness units by sitting next to Eric. +Frank would gain 18 happiness units by sitting next to George. +Frank would lose 56 happiness units by sitting next to Mallory. +George would gain 45 happiness units by sitting next to Alice. +George would gain 76 happiness units by sitting next to Bob. +George would gain 63 happiness units by sitting next to Carol. +George would gain 54 happiness units by sitting next to David. +George would gain 54 happiness units by sitting next to Eric. +George would gain 30 happiness units by sitting next to Frank. +George would gain 7 happiness units by sitting next to Mallory. +Mallory would gain 31 happiness units by sitting next to Alice. +Mallory would lose 32 happiness units by sitting next to Bob. +Mallory would gain 95 happiness units by sitting next to Carol. +Mallory would gain 91 happiness units by sitting next to David. +Mallory would lose 66 happiness units by sitting next to Eric. +Mallory would lose 75 happiness units by sitting next to Frank. +Mallory would lose 99 happiness units by sitting next to George. +""" + +let regex = try! NSRegularExpression(pattern: #"^([a-z]+) would (gain|lose) (\d+) happiness units by sitting next to ([a-z]+)\.$"#, options: [.anchorsMatchLines, .caseInsensitive]) + +let matches = regex.matches(in: input, options: []) + +var scores: [Substring: [Substring: Int]] = [:] + +for match in matches { + let parts = match.matches(in: input) + let personA = parts[1] + let sign = parts[2] == "gain" ? 1 : -1 + let points = sign * Int(parts[3])! + let personB = parts[4] + + scores[personA, default: [:]][personB] = points +} + +func scoreFor(_ a: Substring, _ b: Substring) -> Int { + if a == "me" || b == "me" { + return 0 + } + + return scores[a]![b]! + scores[b]![a]! +} + +extension Collection where Element: Equatable { + func permutations() -> [[Element]] { + if count == 0 { + return [] + } + + if count == 1 { + return [[self[self.startIndex]]] + } + + var result: [[Element]] = [] + for element in self { + let rest = self.filter { $0 != element } + result.append(contentsOf: rest.permutations().map { + [element] + $0 + }) + } + + return result + } +} + +func calculateScore(_ order: [Substring]) -> Int { + var current = order.first! + var score = 0 + for next in order.dropFirst() { + score += scoreFor(current, next) + current = next + } + score += scoreFor(current, order.first!) + return score +} + +let maxScore = scores.keys.permutations().map { + calculateScore($0) +}.max()! + +print(maxScore) + +let maxScoreWithMe = (["me"] + Array(scores.keys)).permutations().map { + calculateScore($0) +}.max()! + +print("Including me:", maxScoreWithMe) + +extension NSRegularExpression { + func matches(in string: String, options: NSRegularExpression.MatchingOptions = []) -> [NSTextCheckingResult] { + let range = NSRange(string.startIndex..., in: string) + return matches(in: input, options: options, range: range) + } +} + +extension NSTextCheckingResult { + struct Matches: BidirectionalCollection { + typealias Element = Substring + + struct Index: Comparable { + let position: Int + + static func <(lhs: Index, rhs: Index) -> Bool { + return lhs.position < rhs.position + } + + } + + func index(after i: Index) -> Index { + Index(position: i.position + 1) + } + + func index(before i: Index) -> Index { + Index(position: i.position - 1) + } + + + let result: NSTextCheckingResult + let wholeString: String + + var startIndex: Index { Index(position: 0) } + var endIndex: Index { Index(position: result.numberOfRanges) } + + subscript(position: Index) -> Element { + let range = Range(result.range(at: position.position), in: wholeString)! + return wholeString[range] + } + + subscript(name: String) -> Element? { + let range = result.range(withName: name) + guard range.lowerBound != NSNotFound, let range = Range(range, in: wholeString) else { return nil } + return wholeString[range] + } + } + + func matches(in string: String) -> Matches { + .init(result: self, wholeString: string) + } +} + +extension NSTextCheckingResult.Matches.Index: ExpressibleByIntegerLiteral { + init(integerLiteral value: Int) { + self.position = value + } + +} diff --git a/2015/Day14.playground/Contents.swift b/2015/Day14.playground/Contents.swift new file mode 100644 index 0000000..38aabba --- /dev/null +++ b/2015/Day14.playground/Contents.swift @@ -0,0 +1,82 @@ +import Foundation + +let regex = try! NSRegularExpression(pattern: #"^([a-z]+) can fly (\d+) km/s for (\d+) seconds, but then must rest for (\d+) seconds.$"#, options: [.caseInsensitive, .anchorsMatchLines]) + +struct Reindeer { + var name: String + var flySpeed: Int + var flyDuration: Int + var restDuration: Int + + var duration: Int + var resting: Bool = false + var distance: Int = 0 + var points: Int = 0 + + mutating func step() { + duration -= 1 + if !resting { + distance += flySpeed + } + + if duration == 0 { + resting.toggle() + duration = resting ? restDuration : flyDuration + } + } + + static func parse(_ input: String) -> [Reindeer] { + let matches = regex.matches(in: input, options: [], range: NSRange(input.startIndex..., in: input)) + return matches.map { Reindeer(match: $0, in: input) } + } + + init(match: NSTextCheckingResult, in string: String) { + name = String(match.string(index: 1, in: string)) + flySpeed = Int(match.string(index: 2, in: string))! + flyDuration = Int(match.string(index: 3, in: string))! + restDuration = Int(match.string(index: 4, in: string))! + + duration = flyDuration + } +} + +extension NSTextCheckingResult { + func string(index: Int, in string: String) -> Substring { + let range = Range(self.range(at: index), in: string)! + return string[range] + } +} + +let input = """ +Vixen can fly 19 km/s for 7 seconds, but then must rest for 124 seconds. +Rudolph can fly 3 km/s for 15 seconds, but then must rest for 28 seconds. +Donner can fly 19 km/s for 9 seconds, but then must rest for 164 seconds. +Blitzen can fly 19 km/s for 9 seconds, but then must rest for 158 seconds. +Comet can fly 13 km/s for 7 seconds, but then must rest for 82 seconds. +Cupid can fly 25 km/s for 6 seconds, but then must rest for 145 seconds. +Dasher can fly 14 km/s for 3 seconds, but then must rest for 38 seconds. +Dancer can fly 3 km/s for 16 seconds, but then must rest for 37 seconds. +Prancer can fly 25 km/s for 6 seconds, but then must rest for 143 seconds. +""" + + +var group = Reindeer.parse(input) + +for _ in 0..<2503 { + for i in group.indices { + group[i].step() + } + + let lead = group.map(\.distance).max()! + + for i in group.indices where group[i].distance == lead { + group[i].points += 1 + } +} + +group + +group + .sorted { $0.points > $1.points } + .first + diff --git a/2015/Day14.playground/contents.xcplayground b/2015/Day14.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day14.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day14.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day14.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day14.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day14.playground/timeline.xctimeline b/2015/Day14.playground/timeline.xctimeline new file mode 100644 index 0000000..bf468af --- /dev/null +++ b/2015/Day14.playground/timeline.xctimeline @@ -0,0 +1,6 @@ + + + + + diff --git a/2015/Day14/main.swift b/2015/Day14/main.swift new file mode 100644 index 0000000..88a1dc9 --- /dev/null +++ b/2015/Day14/main.swift @@ -0,0 +1,36 @@ + +/* + Sugar: capacity 3, durability 0, flavor 0, texture -3, calories 2 + Sprinkles: capacity -3, durability 3, flavor 0, texture 0, calories 9 + Candy: capacity -1, durability 0, flavor 4, texture 0, calories 1 + Chocolate: capacity 0, durability 0, flavor -2, texture 2, calories 8 + */ + +var score = 0 +var scoreFor500 = 0 + +for a in 0...100 { + for b in 0...(100-a) { + for c in 0...(100-a-b) { + for d in 0...(100-a-b-c) where a + b + c + d == 100 { + let capacity = 3 * a - 3 * b - c + let durability = 3 * b + let flavor = 4 * c - 2 * d + let texture = -3 * a + 2 * d + let calories = 2 * a + 9 * b + c + 8 * d + + let currentScore = max(0,capacity) * max(0,durability) * max(0,flavor) * max(0,texture) + if currentScore > score { + score = currentScore + } + + + if calories == 500, currentScore > scoreFor500 { + scoreFor500 = currentScore + } + } + } + } +} + +print(score, scoreFor500) diff --git a/2015/Day16/main.swift b/2015/Day16/main.swift new file mode 100644 index 0000000..53d4465 --- /dev/null +++ b/2015/Day16/main.swift @@ -0,0 +1,571 @@ +import Foundation + +let input = """ +Sue 1: children: 1, cars: 8, vizslas: 7 +Sue 2: akitas: 10, perfumes: 10, children: 5 +Sue 3: cars: 5, pomeranians: 4, vizslas: 1 +Sue 4: goldfish: 5, children: 8, perfumes: 3 +Sue 5: vizslas: 2, akitas: 7, perfumes: 6 +Sue 6: vizslas: 0, akitas: 1, perfumes: 2 +Sue 7: perfumes: 8, cars: 4, goldfish: 10 +Sue 8: perfumes: 7, children: 2, cats: 1 +Sue 9: pomeranians: 3, goldfish: 10, trees: 10 +Sue 10: akitas: 7, trees: 8, pomeranians: 4 +Sue 11: goldfish: 1, perfumes: 4, cars: 6 +Sue 12: samoyeds: 6, trees: 6, perfumes: 2 +Sue 13: akitas: 10, pomeranians: 0, vizslas: 2 +Sue 14: cars: 2, perfumes: 3, children: 4 +Sue 15: goldfish: 2, children: 8, cars: 5 +Sue 16: goldfish: 9, cars: 0, vizslas: 5 +Sue 17: cats: 5, trees: 6, perfumes: 6 +Sue 18: cars: 0, perfumes: 8, pomeranians: 7 +Sue 19: trees: 2, goldfish: 5, perfumes: 4 +Sue 20: akitas: 4, vizslas: 4, trees: 0 +Sue 21: pomeranians: 7, trees: 0, goldfish: 10 +Sue 22: cars: 4, vizslas: 0, perfumes: 3 +Sue 23: vizslas: 8, trees: 1, akitas: 2 +Sue 24: children: 7, trees: 0, akitas: 1 +Sue 25: goldfish: 3, akitas: 2, trees: 2 +Sue 26: pomeranians: 4, vizslas: 4, samoyeds: 2 +Sue 27: cars: 0, trees: 8, akitas: 5 +Sue 28: perfumes: 6, cats: 0, cars: 2 +Sue 29: trees: 7, akitas: 1, vizslas: 1 +Sue 30: perfumes: 9, cars: 9, trees: 10 +Sue 31: pomeranians: 5, akitas: 9, samoyeds: 1 +Sue 32: pomeranians: 10, vizslas: 5, goldfish: 5 +Sue 33: vizslas: 2, akitas: 3, trees: 7 +Sue 34: goldfish: 10, perfumes: 0, samoyeds: 7 +Sue 35: akitas: 6, cats: 7, perfumes: 10 +Sue 36: pomeranians: 8, vizslas: 7, akitas: 6 +Sue 37: goldfish: 2, cars: 10, children: 7 +Sue 38: goldfish: 2, perfumes: 3, cars: 7 +Sue 39: trees: 9, vizslas: 10, cars: 5 +Sue 40: goldfish: 1, pomeranians: 0, trees: 2 +Sue 41: trees: 2, goldfish: 6, vizslas: 3 +Sue 42: akitas: 1, cars: 3, vizslas: 3 +Sue 43: akitas: 1, pomeranians: 1, vizslas: 3 +Sue 44: goldfish: 7, akitas: 3, vizslas: 10 +Sue 45: akitas: 8, samoyeds: 8, goldfish: 2 +Sue 46: trees: 0, vizslas: 4, cars: 9 +Sue 47: cars: 9, trees: 10, perfumes: 4 +Sue 48: akitas: 0, vizslas: 5, perfumes: 4 +Sue 49: goldfish: 9, trees: 1, cars: 4 +Sue 50: goldfish: 2, perfumes: 5, cars: 2 +Sue 51: samoyeds: 1, goldfish: 2, perfumes: 7 +Sue 52: cars: 0, perfumes: 4, goldfish: 8 +Sue 53: goldfish: 9, vizslas: 2, akitas: 9 +Sue 54: trees: 1, goldfish: 9, children: 5 +Sue 55: cars: 0, akitas: 5, trees: 4 +Sue 56: trees: 4, samoyeds: 5, children: 9 +Sue 57: children: 0, vizslas: 8, cars: 3 +Sue 58: trees: 4, pomeranians: 5, akitas: 5 +Sue 59: vizslas: 10, cats: 3, children: 2 +Sue 60: cats: 6, vizslas: 2, cars: 2 +Sue 61: akitas: 1, vizslas: 0, children: 4 +Sue 62: akitas: 4, trees: 9, children: 10 +Sue 63: pomeranians: 6, vizslas: 6, cars: 4 +Sue 64: perfumes: 8, pomeranians: 1, children: 8 +Sue 65: perfumes: 3, goldfish: 6, trees: 5 +Sue 66: goldfish: 10, akitas: 8, vizslas: 4 +Sue 67: vizslas: 10, samoyeds: 3, trees: 2 +Sue 68: samoyeds: 4, cars: 7, perfumes: 3 +Sue 69: perfumes: 2, goldfish: 0, trees: 2 +Sue 70: trees: 8, vizslas: 7, akitas: 6 +Sue 71: cars: 2, children: 7, perfumes: 3 +Sue 72: cars: 1, akitas: 9, perfumes: 0 +Sue 73: vizslas: 4, akitas: 7, cars: 5 +Sue 74: samoyeds: 3, cars: 3, akitas: 2 +Sue 75: trees: 2, cars: 1, vizslas: 7 +Sue 76: samoyeds: 9, perfumes: 1, trees: 6 +Sue 77: trees: 6, perfumes: 10, cars: 7 +Sue 78: trees: 0, children: 8, vizslas: 5 +Sue 79: vizslas: 0, trees: 0, samoyeds: 1 +Sue 80: trees: 6, goldfish: 8, perfumes: 0 +Sue 81: samoyeds: 8, pomeranians: 6, akitas: 5 +Sue 82: vizslas: 6, perfumes: 9, akitas: 4 +Sue 83: cats: 0, vizslas: 3, pomeranians: 10 +Sue 84: cars: 4, perfumes: 6, samoyeds: 5 +Sue 85: vizslas: 7, trees: 5, goldfish: 7 +Sue 86: goldfish: 2, trees: 2, vizslas: 1 +Sue 87: trees: 6, goldfish: 10, pomeranians: 4 +Sue 88: vizslas: 1, akitas: 0, perfumes: 8 +Sue 89: goldfish: 8, akitas: 3, vizslas: 7 +Sue 90: vizslas: 9, akitas: 7, perfumes: 9 +Sue 91: children: 7, cars: 7, trees: 9 +Sue 92: vizslas: 10, akitas: 8, goldfish: 1 +Sue 93: goldfish: 7, vizslas: 2, pomeranians: 0 +Sue 94: cats: 2, samoyeds: 6, pomeranians: 3 +Sue 95: samoyeds: 4, children: 4, pomeranians: 10 +Sue 96: pomeranians: 9, cats: 1, goldfish: 3 +Sue 97: trees: 1, akitas: 6, goldfish: 1 +Sue 98: vizslas: 7, akitas: 2, perfumes: 7 +Sue 99: pomeranians: 6, perfumes: 2, trees: 1 +Sue 100: cars: 3, children: 9, trees: 10 +Sue 101: children: 0, perfumes: 0, vizslas: 3 +Sue 102: cars: 4, goldfish: 5, children: 2 +Sue 103: pomeranians: 3, perfumes: 7, cats: 8 +Sue 104: akitas: 0, perfumes: 5, vizslas: 5 +Sue 105: akitas: 7, vizslas: 2, samoyeds: 8 +Sue 106: goldfish: 7, perfumes: 0, cats: 8 +Sue 107: cats: 6, pomeranians: 9, cars: 6 +Sue 108: akitas: 3, vizslas: 10, cats: 5 +Sue 109: akitas: 10, perfumes: 2, cars: 7 +Sue 110: goldfish: 7, pomeranians: 1, trees: 1 +Sue 111: akitas: 10, samoyeds: 6, vizslas: 6 +Sue 112: cats: 6, akitas: 7, trees: 9 +Sue 113: akitas: 1, trees: 9, vizslas: 8 +Sue 114: vizslas: 2, cats: 1, cars: 4 +Sue 115: akitas: 0, trees: 5, goldfish: 7 +Sue 116: goldfish: 2, trees: 10, akitas: 2 +Sue 117: cars: 4, goldfish: 10, perfumes: 5 +Sue 118: cars: 5, perfumes: 6, trees: 0 +Sue 119: perfumes: 5, vizslas: 1, cats: 0 +Sue 120: perfumes: 8, akitas: 9, vizslas: 4 +Sue 121: samoyeds: 2, vizslas: 7, perfumes: 6 +Sue 122: children: 6, trees: 9, perfumes: 2 +Sue 123: cars: 7, akitas: 0, pomeranians: 0 +Sue 124: akitas: 7, cats: 8, vizslas: 5 +Sue 125: goldfish: 3, trees: 1, cars: 4 +Sue 126: cars: 4, perfumes: 3, akitas: 0 +Sue 127: children: 10, vizslas: 5, akitas: 9 +Sue 128: akitas: 3, samoyeds: 2, cats: 8 +Sue 129: cats: 8, akitas: 1, vizslas: 8 +Sue 130: trees: 4, cars: 6, perfumes: 6 +Sue 131: akitas: 7, perfumes: 6, goldfish: 9 +Sue 132: akitas: 6, vizslas: 7, trees: 1 +Sue 133: akitas: 5, vizslas: 7, children: 9 +Sue 134: cars: 8, goldfish: 4, pomeranians: 4 +Sue 135: samoyeds: 1, pomeranians: 6, akitas: 4 +Sue 136: perfumes: 10, goldfish: 1, cars: 3 +Sue 137: cars: 3, samoyeds: 6, vizslas: 7 +Sue 138: samoyeds: 10, akitas: 3, perfumes: 4 +Sue 139: perfumes: 10, vizslas: 2, goldfish: 7 +Sue 140: samoyeds: 7, cars: 1, trees: 2 +Sue 141: children: 6, cats: 5, cars: 9 +Sue 142: cats: 0, trees: 1, akitas: 10 +Sue 143: samoyeds: 4, cars: 0, children: 7 +Sue 144: trees: 0, cars: 4, perfumes: 8 +Sue 145: goldfish: 7, cars: 5, trees: 1 +Sue 146: perfumes: 7, cars: 7, goldfish: 0 +Sue 147: trees: 2, goldfish: 7, vizslas: 5 +Sue 148: samoyeds: 8, perfumes: 1, trees: 0 +Sue 149: vizslas: 2, samoyeds: 5, trees: 0 +Sue 150: akitas: 4, perfumes: 4, pomeranians: 2 +Sue 151: trees: 2, cars: 0, goldfish: 10 +Sue 152: goldfish: 7, vizslas: 0, trees: 0 +Sue 153: children: 9, cats: 0, pomeranians: 10 +Sue 154: cars: 6, goldfish: 10, akitas: 5 +Sue 155: perfumes: 9, trees: 2, akitas: 3 +Sue 156: pomeranians: 9, perfumes: 5, cars: 9 +Sue 157: akitas: 0, trees: 2, cars: 7 +Sue 158: goldfish: 10, trees: 8, akitas: 7 +Sue 159: akitas: 5, trees: 10, cars: 10 +Sue 160: akitas: 3, trees: 5, cars: 8 +Sue 161: samoyeds: 2, cars: 7, perfumes: 4 +Sue 162: cars: 6, vizslas: 10, pomeranians: 5 +Sue 163: cars: 10, perfumes: 6, vizslas: 9 +Sue 164: pomeranians: 7, cars: 4, vizslas: 2 +Sue 165: goldfish: 9, vizslas: 3, trees: 1 +Sue 166: goldfish: 1, samoyeds: 3, trees: 1 +Sue 167: vizslas: 4, goldfish: 7, cats: 5 +Sue 168: children: 1, cars: 5, samoyeds: 7 +Sue 169: trees: 1, samoyeds: 3, goldfish: 6 +Sue 170: goldfish: 2, cars: 3, perfumes: 9 +Sue 171: cars: 4, goldfish: 0, trees: 6 +Sue 172: cats: 8, perfumes: 6, trees: 1 +Sue 173: akitas: 9, goldfish: 7, cars: 10 +Sue 174: vizslas: 2, trees: 0, akitas: 1 +Sue 175: perfumes: 3, vizslas: 8, akitas: 4 +Sue 176: perfumes: 0, akitas: 6, goldfish: 3 +Sue 177: perfumes: 6, children: 1, goldfish: 10 +Sue 178: cars: 5, vizslas: 3, children: 10 +Sue 179: perfumes: 3, trees: 8, cats: 9 +Sue 180: perfumes: 8, vizslas: 4, trees: 7 +Sue 181: perfumes: 7, vizslas: 9, samoyeds: 4 +Sue 182: vizslas: 9, trees: 4, pomeranians: 4 +Sue 183: trees: 9, cars: 3, goldfish: 5 +Sue 184: perfumes: 2, cars: 4, vizslas: 3 +Sue 185: children: 10, akitas: 10, cats: 9 +Sue 186: cars: 5, samoyeds: 0, trees: 0 +Sue 187: trees: 2, goldfish: 3, cars: 4 +Sue 188: goldfish: 3, vizslas: 1, cats: 6 +Sue 189: trees: 2, pomeranians: 10, cars: 7 +Sue 190: perfumes: 10, akitas: 3, samoyeds: 0 +Sue 191: cats: 5, vizslas: 6, akitas: 6 +Sue 192: samoyeds: 5, trees: 1, perfumes: 8 +Sue 193: pomeranians: 0, akitas: 9, cats: 0 +Sue 194: trees: 1, goldfish: 0, perfumes: 10 +Sue 195: perfumes: 2, akitas: 7, cars: 5 +Sue 196: perfumes: 5, samoyeds: 8, cars: 1 +Sue 197: vizslas: 2, pomeranians: 9, trees: 1 +Sue 198: trees: 8, vizslas: 6, children: 8 +Sue 199: pomeranians: 4, cars: 7, vizslas: 5 +Sue 200: trees: 0, perfumes: 10, akitas: 10 +Sue 201: cats: 9, akitas: 4, vizslas: 0 +Sue 202: goldfish: 9, pomeranians: 9, cats: 6 +Sue 203: cars: 5, perfumes: 5, trees: 2 +Sue 204: pomeranians: 7, children: 2, akitas: 6 +Sue 205: samoyeds: 7, pomeranians: 7, children: 6 +Sue 206: trees: 1, cars: 1, pomeranians: 4 +Sue 207: goldfish: 2, perfumes: 5, trees: 0 +Sue 208: perfumes: 2, samoyeds: 4, trees: 1 +Sue 209: cars: 8, perfumes: 6, goldfish: 9 +Sue 210: perfumes: 4, cars: 8, samoyeds: 3 +Sue 211: perfumes: 2, cars: 8, trees: 9 +Sue 212: trees: 7, perfumes: 2, akitas: 5 +Sue 213: children: 3, goldfish: 5, vizslas: 0 +Sue 214: akitas: 6, goldfish: 0, children: 0 +Sue 215: trees: 8, akitas: 3, goldfish: 1 +Sue 216: goldfish: 6, perfumes: 8, akitas: 3 +Sue 217: children: 7, trees: 2, vizslas: 6 +Sue 218: goldfish: 8, samoyeds: 4, pomeranians: 6 +Sue 219: goldfish: 8, samoyeds: 0, children: 9 +Sue 220: perfumes: 1, cars: 8, vizslas: 6 +Sue 221: perfumes: 9, cars: 10, children: 10 +Sue 222: perfumes: 9, vizslas: 1, trees: 0 +Sue 223: goldfish: 1, akitas: 2, vizslas: 8 +Sue 224: samoyeds: 8, akitas: 7, vizslas: 4 +Sue 225: goldfish: 1, cars: 4, perfumes: 10 +Sue 226: goldfish: 9, trees: 4, perfumes: 5 +Sue 227: vizslas: 5, trees: 4, goldfish: 7 +Sue 228: cars: 1, cats: 10, perfumes: 4 +Sue 229: vizslas: 8, cars: 10, akitas: 4 +Sue 230: cats: 1, children: 8, vizslas: 3 +Sue 231: perfumes: 7, cats: 6, samoyeds: 7 +Sue 232: cars: 3, children: 9, perfumes: 7 +Sue 233: vizslas: 1, samoyeds: 2, children: 2 +Sue 234: trees: 1, samoyeds: 8, children: 2 +Sue 235: trees: 6, akitas: 9, goldfish: 7 +Sue 236: children: 10, trees: 0, samoyeds: 8 +Sue 237: pomeranians: 4, trees: 1, goldfish: 2 +Sue 238: vizslas: 4, akitas: 2, cars: 0 +Sue 239: goldfish: 9, cars: 10, perfumes: 4 +Sue 240: perfumes: 3, vizslas: 6, trees: 6 +Sue 241: pomeranians: 6, akitas: 4, trees: 2 +Sue 242: cars: 8, perfumes: 5, children: 7 +Sue 243: trees: 4, perfumes: 7, cars: 3 +Sue 244: perfumes: 6, akitas: 1, vizslas: 7 +Sue 245: akitas: 3, perfumes: 9, samoyeds: 0 +Sue 246: pomeranians: 3, vizslas: 9, samoyeds: 1 +Sue 247: cars: 0, goldfish: 7, cats: 2 +Sue 248: trees: 5, goldfish: 6, perfumes: 3 +Sue 249: trees: 0, pomeranians: 7, perfumes: 9 +Sue 250: cars: 9, trees: 1, goldfish: 10 +Sue 251: perfumes: 3, cars: 8, trees: 7 +Sue 252: cars: 5, akitas: 7, trees: 8 +Sue 253: perfumes: 7, akitas: 3, trees: 8 +Sue 254: goldfish: 8, samoyeds: 1, vizslas: 7 +Sue 255: perfumes: 3, cars: 4, children: 6 +Sue 256: perfumes: 9, trees: 8, children: 7 +Sue 257: trees: 8, children: 6, cars: 4 +Sue 258: vizslas: 1, trees: 10, goldfish: 9 +Sue 259: vizslas: 5, trees: 6, goldfish: 9 +Sue 260: trees: 0, goldfish: 6, cars: 7 +Sue 261: cars: 1, perfumes: 4, goldfish: 9 +Sue 262: cars: 7, goldfish: 9, cats: 9 +Sue 263: cars: 0, children: 5, goldfish: 8 +Sue 264: cars: 2, akitas: 8, trees: 0 +Sue 265: perfumes: 9, children: 8, samoyeds: 7 +Sue 266: cats: 1, children: 1, vizslas: 10 +Sue 267: vizslas: 8, children: 2, trees: 6 +Sue 268: akitas: 10, vizslas: 3, cats: 2 +Sue 269: children: 4, goldfish: 1, cats: 6 +Sue 270: vizslas: 5, cars: 9, akitas: 9 +Sue 271: vizslas: 5, children: 4, akitas: 3 +Sue 272: cars: 1, goldfish: 0, vizslas: 0 +Sue 273: goldfish: 10, samoyeds: 1, akitas: 2 +Sue 274: goldfish: 10, children: 2, pomeranians: 0 +Sue 275: children: 0, vizslas: 1, samoyeds: 6 +Sue 276: children: 1, vizslas: 3, samoyeds: 1 +Sue 277: perfumes: 4, cats: 6, children: 10 +Sue 278: pomeranians: 7, goldfish: 3, cars: 4 +Sue 279: perfumes: 5, goldfish: 9, trees: 7 +Sue 280: goldfish: 6, trees: 5, perfumes: 8 +Sue 281: cars: 2, akitas: 1, vizslas: 7 +Sue 282: vizslas: 4, akitas: 3, children: 8 +Sue 283: pomeranians: 8, akitas: 9, vizslas: 4 +Sue 284: samoyeds: 10, trees: 10, pomeranians: 2 +Sue 285: akitas: 9, perfumes: 7, goldfish: 6 +Sue 286: akitas: 2, vizslas: 7, goldfish: 10 +Sue 287: pomeranians: 8, cars: 6, samoyeds: 5 +Sue 288: pomeranians: 1, trees: 0, goldfish: 0 +Sue 289: trees: 10, samoyeds: 1, children: 0 +Sue 290: cats: 10, samoyeds: 6, trees: 0 +Sue 291: vizslas: 9, trees: 6, goldfish: 5 +Sue 292: cats: 4, perfumes: 8, cars: 3 +Sue 293: goldfish: 10, perfumes: 10, cats: 0 +Sue 294: cats: 7, trees: 6, akitas: 4 +Sue 295: vizslas: 8, cars: 1, akitas: 6 +Sue 296: vizslas: 5, akitas: 10, trees: 1 +Sue 297: pomeranians: 8, samoyeds: 5, vizslas: 4 +Sue 298: perfumes: 10, children: 5, vizslas: 2 +Sue 299: cars: 10, akitas: 7, cats: 5 +Sue 300: trees: 1, perfumes: 7, cars: 7 +Sue 301: cars: 9, vizslas: 1, perfumes: 3 +Sue 302: perfumes: 9, vizslas: 1, akitas: 5 +Sue 303: akitas: 9, trees: 1, goldfish: 10 +Sue 304: children: 10, vizslas: 6, pomeranians: 8 +Sue 305: trees: 3, goldfish: 6, cats: 9 +Sue 306: cars: 5, perfumes: 9, vizslas: 5 +Sue 307: children: 0, goldfish: 7, trees: 2 +Sue 308: trees: 9, samoyeds: 4, cars: 0 +Sue 309: cats: 8, vizslas: 2, perfumes: 3 +Sue 310: cars: 6, pomeranians: 6, vizslas: 6 +Sue 311: vizslas: 6, akitas: 7, cats: 10 +Sue 312: trees: 0, goldfish: 7, cars: 0 +Sue 313: perfumes: 5, akitas: 5, cars: 2 +Sue 314: akitas: 10, vizslas: 3, samoyeds: 8 +Sue 315: cars: 3, perfumes: 1, goldfish: 8 +Sue 316: pomeranians: 6, goldfish: 9, perfumes: 1 +Sue 317: goldfish: 4, akitas: 6, cars: 2 +Sue 318: perfumes: 8, vizslas: 8, akitas: 0 +Sue 319: akitas: 10, cars: 5, vizslas: 6 +Sue 320: vizslas: 4, akitas: 3, cats: 4 +Sue 321: goldfish: 4, akitas: 8, cars: 8 +Sue 322: pomeranians: 5, vizslas: 7, cats: 1 +Sue 323: perfumes: 1, trees: 6, goldfish: 0 +Sue 324: goldfish: 6, trees: 10, cars: 10 +Sue 325: akitas: 2, samoyeds: 6, trees: 9 +Sue 326: vizslas: 4, akitas: 7, cars: 9 +Sue 327: children: 3, perfumes: 4, cars: 1 +Sue 328: akitas: 9, perfumes: 6, cars: 10 +Sue 329: perfumes: 2, goldfish: 0, trees: 1 +Sue 330: vizslas: 10, pomeranians: 7, goldfish: 6 +Sue 331: trees: 3, vizslas: 8, cars: 3 +Sue 332: akitas: 2, cats: 1, goldfish: 8 +Sue 333: cars: 6, trees: 2, vizslas: 0 +Sue 334: samoyeds: 7, cars: 7, trees: 3 +Sue 335: cats: 7, children: 1, perfumes: 8 +Sue 336: akitas: 5, goldfish: 10, vizslas: 5 +Sue 337: cats: 3, vizslas: 0, akitas: 10 +Sue 338: perfumes: 8, cars: 1, trees: 8 +Sue 339: cars: 4, samoyeds: 8, children: 2 +Sue 340: goldfish: 9, pomeranians: 1, samoyeds: 1 +Sue 341: akitas: 3, trees: 0, goldfish: 2 +Sue 342: perfumes: 4, vizslas: 8, pomeranians: 9 +Sue 343: akitas: 4, cars: 5, goldfish: 4 +Sue 344: samoyeds: 5, cats: 4, trees: 0 +Sue 345: samoyeds: 4, cars: 8, akitas: 2 +Sue 346: akitas: 3, vizslas: 10, perfumes: 10 +Sue 347: goldfish: 10, akitas: 4, cars: 1 +Sue 348: perfumes: 10, cats: 4, vizslas: 5 +Sue 349: akitas: 2, vizslas: 4, cars: 7 +Sue 350: akitas: 5, vizslas: 5, cars: 6 +Sue 351: vizslas: 8, perfumes: 6, cars: 3 +Sue 352: cars: 10, vizslas: 0, goldfish: 10 +Sue 353: cars: 10, perfumes: 5, children: 7 +Sue 354: vizslas: 6, akitas: 3, samoyeds: 9 +Sue 355: akitas: 2, perfumes: 7, cars: 10 +Sue 356: cars: 10, perfumes: 7, children: 6 +Sue 357: akitas: 4, cars: 8, trees: 1 +Sue 358: trees: 2, cars: 1, goldfish: 2 +Sue 359: vizslas: 5, cars: 9, trees: 4 +Sue 360: perfumes: 4, akitas: 3, cars: 3 +Sue 361: children: 3, akitas: 2, cats: 5 +Sue 362: cars: 8, cats: 4, akitas: 10 +Sue 363: cats: 2, trees: 1, vizslas: 4 +Sue 364: vizslas: 2, pomeranians: 5, samoyeds: 9 +Sue 365: samoyeds: 2, akitas: 7, goldfish: 9 +Sue 366: goldfish: 8, trees: 7, cats: 2 +Sue 367: perfumes: 2, vizslas: 6, trees: 5 +Sue 368: cars: 5, samoyeds: 0, perfumes: 6 +Sue 369: samoyeds: 10, trees: 10, vizslas: 1 +Sue 370: trees: 2, vizslas: 3, cars: 4 +Sue 371: akitas: 6, pomeranians: 2, cats: 4 +Sue 372: trees: 2, perfumes: 3, goldfish: 9 +Sue 373: vizslas: 5, children: 0, pomeranians: 6 +Sue 374: trees: 1, vizslas: 8, perfumes: 10 +Sue 375: cars: 0, akitas: 6, children: 0 +Sue 376: akitas: 1, vizslas: 0, trees: 0 +Sue 377: samoyeds: 10, cats: 5, pomeranians: 0 +Sue 378: goldfish: 3, pomeranians: 7, cats: 7 +Sue 379: perfumes: 0, cats: 0, trees: 8 +Sue 380: perfumes: 4, samoyeds: 1, akitas: 7 +Sue 381: akitas: 4, pomeranians: 2, children: 4 +Sue 382: vizslas: 9, akitas: 4, trees: 10 +Sue 383: trees: 1, vizslas: 10, akitas: 6 +Sue 384: trees: 3, akitas: 8, goldfish: 3 +Sue 385: goldfish: 6, perfumes: 2, children: 9 +Sue 386: children: 10, akitas: 7, goldfish: 7 +Sue 387: goldfish: 3, vizslas: 10, perfumes: 5 +Sue 388: children: 4, trees: 0, cars: 2 +Sue 389: trees: 0, cats: 3, goldfish: 10 +Sue 390: samoyeds: 9, pomeranians: 0, cats: 6 +Sue 391: samoyeds: 10, trees: 3, akitas: 4 +Sue 392: akitas: 9, goldfish: 10, perfumes: 7 +Sue 393: goldfish: 6, cars: 2, akitas: 9 +Sue 394: trees: 4, goldfish: 9, vizslas: 7 +Sue 395: vizslas: 4, samoyeds: 1, goldfish: 6 +Sue 396: vizslas: 5, cats: 0, samoyeds: 1 +Sue 397: goldfish: 7, cats: 0, trees: 7 +Sue 398: cars: 10, akitas: 1, vizslas: 7 +Sue 399: samoyeds: 10, cats: 6, goldfish: 6 +Sue 400: cats: 6, samoyeds: 0, trees: 2 +Sue 401: trees: 1, children: 4, goldfish: 2 +Sue 402: cats: 8, vizslas: 4, children: 3 +Sue 403: cars: 9, perfumes: 8, pomeranians: 2 +Sue 404: goldfish: 8, trees: 2, cars: 5 +Sue 405: perfumes: 1, pomeranians: 5, vizslas: 5 +Sue 406: perfumes: 6, trees: 2, pomeranians: 6 +Sue 407: trees: 0, goldfish: 6, cars: 6 +Sue 408: trees: 0, samoyeds: 7, goldfish: 9 +Sue 409: samoyeds: 10, goldfish: 6, pomeranians: 0 +Sue 410: perfumes: 5, vizslas: 6, trees: 0 +Sue 411: goldfish: 2, trees: 2, pomeranians: 0 +Sue 412: pomeranians: 4, perfumes: 8, cats: 8 +Sue 413: vizslas: 4, cars: 5, akitas: 1 +Sue 414: perfumes: 2, trees: 8, goldfish: 7 +Sue 415: akitas: 3, trees: 1, perfumes: 3 +Sue 416: cars: 7, trees: 1, perfumes: 8 +Sue 417: cars: 5, goldfish: 5, trees: 1 +Sue 418: cars: 9, goldfish: 4, samoyeds: 2 +Sue 419: pomeranians: 8, akitas: 1, goldfish: 6 +Sue 420: cars: 0, cats: 0, children: 8 +Sue 421: akitas: 10, goldfish: 1, vizslas: 8 +Sue 422: children: 8, vizslas: 6, samoyeds: 10 +Sue 423: samoyeds: 3, goldfish: 10, vizslas: 8 +Sue 424: cars: 3, children: 7, goldfish: 4 +Sue 425: cars: 9, perfumes: 9, goldfish: 8 +Sue 426: akitas: 5, trees: 10, vizslas: 10 +Sue 427: vizslas: 10, cars: 3, akitas: 7 +Sue 428: cats: 6, perfumes: 5, goldfish: 10 +Sue 429: goldfish: 7, trees: 5, vizslas: 10 +Sue 430: perfumes: 3, trees: 7, cars: 3 +Sue 431: cars: 2, vizslas: 1, akitas: 6 +Sue 432: pomeranians: 8, perfumes: 5, cars: 3 +Sue 433: children: 8, cars: 0, perfumes: 7 +Sue 434: samoyeds: 0, vizslas: 9, akitas: 10 +Sue 435: akitas: 3, vizslas: 8, cats: 4 +Sue 436: goldfish: 5, trees: 8, samoyeds: 8 +Sue 437: cars: 10, samoyeds: 9, goldfish: 7 +Sue 438: samoyeds: 5, akitas: 7, perfumes: 9 +Sue 439: goldfish: 10, perfumes: 5, cars: 0 +Sue 440: pomeranians: 1, samoyeds: 9, children: 4 +Sue 441: vizslas: 4, perfumes: 2, cats: 5 +Sue 442: trees: 0, pomeranians: 3, cars: 7 +Sue 443: akitas: 0, cars: 2, vizslas: 10 +Sue 444: children: 1, akitas: 9, trees: 0 +Sue 445: cars: 5, perfumes: 7, goldfish: 9 +Sue 446: akitas: 0, perfumes: 1, vizslas: 2 +Sue 447: vizslas: 7, perfumes: 0, cars: 5 +Sue 448: vizslas: 6, goldfish: 10, trees: 0 +Sue 449: cars: 7, vizslas: 7, trees: 3 +Sue 450: pomeranians: 4, akitas: 4, vizslas: 8 +Sue 451: cats: 4, perfumes: 8, children: 3 +Sue 452: samoyeds: 8, akitas: 9, cars: 1 +Sue 453: cars: 8, akitas: 5, vizslas: 2 +Sue 454: vizslas: 9, perfumes: 4, akitas: 4 +Sue 455: akitas: 3, goldfish: 2, vizslas: 6 +Sue 456: cars: 4, perfumes: 5, goldfish: 10 +Sue 457: trees: 9, pomeranians: 4, goldfish: 10 +Sue 458: pomeranians: 1, perfumes: 9, children: 6 +Sue 459: samoyeds: 0, goldfish: 8, vizslas: 6 +Sue 460: cars: 10, goldfish: 8, samoyeds: 8 +Sue 461: akitas: 8, goldfish: 9, vizslas: 2 +Sue 462: cars: 1, vizslas: 2, akitas: 8 +Sue 463: goldfish: 2, akitas: 4, samoyeds: 10 +Sue 464: children: 5, perfumes: 5, cars: 5 +Sue 465: perfumes: 9, trees: 0, samoyeds: 6 +Sue 466: akitas: 5, goldfish: 3, cats: 6 +Sue 467: perfumes: 3, goldfish: 0, trees: 4 +Sue 468: goldfish: 2, children: 4, trees: 1 +Sue 469: cars: 0, perfumes: 8, children: 7 +Sue 470: vizslas: 8, cats: 5, samoyeds: 9 +Sue 471: pomeranians: 7, trees: 2, goldfish: 3 +Sue 472: goldfish: 8, akitas: 4, perfumes: 5 +Sue 473: perfumes: 2, pomeranians: 3, cars: 8 +Sue 474: samoyeds: 0, akitas: 7, pomeranians: 6 +Sue 475: vizslas: 7, perfumes: 1, trees: 6 +Sue 476: vizslas: 3, samoyeds: 1, perfumes: 10 +Sue 477: cars: 6, perfumes: 5, vizslas: 2 +Sue 478: pomeranians: 1, goldfish: 3, akitas: 7 +Sue 479: goldfish: 10, trees: 0, cars: 3 +Sue 480: cats: 3, akitas: 5, vizslas: 8 +Sue 481: pomeranians: 5, vizslas: 2, trees: 3 +Sue 482: cars: 8, samoyeds: 10, goldfish: 10 +Sue 483: pomeranians: 3, vizslas: 6, goldfish: 5 +Sue 484: perfumes: 7, vizslas: 4, akitas: 7 +Sue 485: goldfish: 1, trees: 0, perfumes: 10 +Sue 486: goldfish: 6, perfumes: 0, akitas: 10 +Sue 487: cats: 2, akitas: 10, trees: 1 +Sue 488: akitas: 1, goldfish: 3, cars: 7 +Sue 489: goldfish: 3, akitas: 6, vizslas: 6 +Sue 490: goldfish: 8, perfumes: 2, akitas: 2 +Sue 491: trees: 4, vizslas: 8, perfumes: 6 +Sue 492: cars: 9, perfumes: 3, cats: 0 +Sue 493: trees: 3, vizslas: 6, goldfish: 7 +Sue 494: trees: 8, samoyeds: 1, perfumes: 5 +Sue 495: children: 9, akitas: 8, vizslas: 4 +Sue 496: vizslas: 2, pomeranians: 1, perfumes: 7 +Sue 497: trees: 2, akitas: 4, vizslas: 6 +Sue 498: akitas: 8, pomeranians: 7, trees: 0 +Sue 499: perfumes: 6, goldfish: 3, vizslas: 7 +Sue 500: cars: 1, perfumes: 6, vizslas: 1 +""" + +let scanner = Scanner(string: input) +scanner.charactersToBeSkipped = .whitespaces + +var sues: [[String: Int]] = [] + +while !scanner.isAtEnd { + var current : [String: Int] = [:] + guard scanner.scanString("Sue") != nil, + let number = scanner.scanInt(), + scanner.scanString(":") != nil else { + preconditionFailure() + } + repeat { + guard let name = scanner.scanUpToString(":"), + scanner.scanString(":") != nil, + let count = scanner.scanInt() else { + preconditionFailure() + } + current[name] = count + } while scanner.scanString(",") != nil + guard scanner.isAtEnd || scanner.scanString("\n") != nil else { + preconditionFailure() + } + sues.append(current) + assert(sues.count == number) +} + +/* + children: 3 + cats: 7 + samoyeds: 2 + pomeranians: 3 + akitas: 0 + vizslas: 0 + goldfish: 5 + trees: 3 + cars: 2 + perfumes: 1 + */ + +extension Dictionary where Key == String, Value == Int { + func matches(_ key: String, count: Int) -> Bool { + //self[key] == nil || self[key] == count + guard let available = self[key] else { return true } + switch key { + case "cats", "trees": return count < available + case "pomeranians", "goldfish": return count > available + default: return count == available + } + } +} + +let possible = sues.enumerated().filter { + $0.element.matches("children", count: 3) && + $0.element.matches("cats", count: 7) && + $0.element.matches("samoyeds", count: 2) && + $0.element.matches("pomeranians", count: 3) && + $0.element.matches("akitas", count: 0) && + $0.element.matches("vizslas", count: 0) && + $0.element.matches("goldfish", count: 5) && + $0.element.matches("trees", count: 3) && + $0.element.matches("cars", count: 2) && + $0.element.matches("perfumes", count: 1) +} + +print(possible) diff --git a/2015/Day17.swift b/2015/Day17.swift new file mode 100644 index 0000000..1462414 --- /dev/null +++ b/2015/Day17.swift @@ -0,0 +1,57 @@ +let input = [ + 43, + 3, + 4, + 10, + 21, + 44, + 4, + 6, + 47, + 41, + 34, + 17, + 17, + 44, + 36, + 31, + 46, + 9, + 27, + 38, +] + +var minLength = Int.max +var minCount = 0 + +func combinations(input: [Int], goal: Int, match: [Int] = []) -> Int { + if goal == 0 { + print("Found", match) + + if match.count < minLength { + minLength = match.count + minCount = 1 + } else if match.count == minLength { + minCount += 1 + } + + return 1 + } + + guard !input.isEmpty else { + return 0 + } + + var result = 0 + for (index, value) in input.enumerated() { + if value <= goal { + var next = Array(input[(index + 1)...]) + result += combinations(input: next, goal: goal - value, match: match + [value]) + } + } + return result +} + +print(combinations(input: input.sorted(by: >), goal: 150)) + +print(minCount) \ No newline at end of file diff --git a/2015/Day18.swift b/2015/Day18.swift new file mode 100644 index 0000000..1cd733d --- /dev/null +++ b/2015/Day18.swift @@ -0,0 +1,153 @@ +let input = """ +#...##......#......##.##..#...##......##.#.#.###.#.#..#..#......####..#......###.#.#....#..##..###..\ +####..#.#...#....#.#####.##.##.#..#.......#....#.##...###.###..#.#.#........#..#.#.##...##..#.####.#\ +...#..##...#.#.###.#.###..#.##.####.###...#...........#.###..##.#.##.#.###...#.#..###....#.###.#..#.\ +.#...##...####.#..#.....#..#...#.#.##...#...##..#.#.###....#..###.....##..#.###..###.....##..###...#\ +..##.#####....##..#.#..##.##..######...#..###.######.....#..##...#.#..##..##..#..#..#..##.#.#.#.#...\ +.###.###.###...##...##..###..##.###.#.....##..##.#.#########...##..##.#..##.#..##..####..#.#.#.#####\ +#.#####..###.###.##.##.#...#.#.#.#..#.###...#..##.###.#...####.#..#.#.....###..#..####..#.#.#...##..\ +....#...##.....#....####.##.#.###..#.#.##..#.#...##.###.###..#.##..#.#.##..##..#.##.###..#.#.###.###\ +##.##...#.##...#.#..#.#..#...###...###.#..#..#.#####..###.#......#.....###.#####.#.#..#.#.#.##..#.#.\ +#.#..#.....#.....##.#..##...###..##...##...###.#.###.#..#.#.###...##..##..#.###...#.#######.#...#.#.\ +#.#.....####.#..#.##...#.##....#####.###.#.....#####....###..#........##..####...#...#.###....#..###\ +##.#.##..#.#.##.#.....##.#.....###.####.#..######.....####.#.#..##.#.##...#..#.#.....#.####.#.......\ +#..#..#.#..#.######.##..##.####.....##.#.##.#.######..#.#....#.#...#.#..#..#.#.###.#..#.#.#..#...###\ +####..####.#.#.###.....#.#.#.##..#.##.##.##.#..##..##.#.##.....#.#..#.####.....###.#..#.####.#.#..##\ +###.##..##.#.##..#..##...#.#####.##.#....##.####.#.##....#..###.#.#.##...#.....#.#.#.#.#..##.#.#..#.\ +......#..####...##.##...#.##.##...##..#..##.###..#...#..##...#.#....###.####...#.##.###.#.##.####.##\ +..#...#####.#.#..#.##....#..#...#..####.....###...##.###....#..#.###...#........#.#.##..#..#.#.....#\ +#######.#.#.###.###..######.##..#####.##.###.###....####.#..##.##...###.#..############.#.##....##.#\ +#.#...##.###.#.###..#.#.#.#.#.#..##..####.#..##.....#.##..#.##...##.#..##..#.#.#....##....##.#..#.#.\ +..#.#.####.....###..#######.#.#.#.#...##.#####.....##...##...##.###..######.###..#...####.#..###.###\ +.#.##....#.#.##..##.#.##.##..######...#.....#..#.#.#.#.....#.#..##.#.#.......#######....#.......#...\ +..###.##.##..##....#.###...#.....##..##......###...##..###.##...##.###.#.#.#.###.###.#.#...###..#...\ +.##.#.#...#...##.#.#...#..#..#.#...##.#.##...##..#....#.#..##.#..#.#..#.#.....#..#.#...#######.#.##.\ +...####....#.###.#..###..##...##..#.#.#.###...#..##.##.##..##.#...#..#.##.....#.#........#..#.#.####\ +.....##..###...#....#.#.#.#...###.###...#.#...#.#.####....#..####...###..#..######..##.##..###.#####\ +#####.##..#....###.###....##.....#.#..#....#.#####.##.#.####.#.##...#..###...###..##...#.###.#####..\ +###.##..........########.######....####.###.#..##...#.##.####.#.....##..#####..###...#####.....#.#.#\ +##..#####.##.#.#####.#.##.##..#.##....########.#####.#...#.###.##...#.###.#.#..#....##.#..#...#.#.#.\ +.##.#....#..#...#..#####..#..##.#......#..#....########...#..#...#.....####.#...##...#.###.#.#..##.#\ +.##.##.#.##.#.##...#.#.#..##.##.###.#..##..#...###.##.###.#####.#.###..#..###.#...#.###.#...#..#.#.#\ +.#..#..#.#..#..###..#....###.####.##.#.###.#.##.###.#.##.###.###...###...###.#...####...#.##.##.#.#.\ +###..##...###...#..##.#..#.#...##....###.##.##..#####....###..#..#....#..###.###.#...#.##...#.#.#..#\ +#....#.......##.....#.##...#..#.###.#.##..##..#.##..#.###..##.##...#####.#..#####..#####..#####....#\ +.####.####....###..###.#.##.####.##.#...####.#.###.#.....#...####..#####.###..#.#.###.##.##...##..#.\ +####..##...##.########...##..###..#..###.##.#.#.#........#.#####.#...#.###.####.#..####..#.#.#....##\ +###.#..#...###.#..#..#.###...##..###.##.#.#...#..#...####..##....#.#..#..##.#.#...#####.###.#..#.#.#\ +...##....#.###.#.#..##...##.###.#..#..#......#...#.#..####.#.##..######.####.#...#..#..#..##.#.#.##.\ +##.####.#...#..#.#.##..##.#.#.###..##...####......#..######.#......#.##.#....##...###.#.#..#......##\ +#.....#...#######.##.#..#.#...###.#..#.####....#.#.##.#.##...###..#...#.###.##..#.###..#.##...#####.\ +#####.##...#..#.#.#.......#.##..#####..#####...###..##.#.#..###.#.#####.####..#.#..##...#.##...#.###\ +.##.#..#######.###.#.####.....##...#.##.#.#..#...##....####......######.#..######.....##########.##.\ +##...#.#..#.##.###.#.#.#.##.###.##..##.##.##...#.#..###.#######..#.....#####..#....######.#..##..###\ +.#.#.###.....#..##..#.#..##..#.###...###.#..##...#...#.#####.#.#####..###.#..#...##..#.#..#..####...\ +.#......##..#.....####.###....##.###.....###.##........#.###.##..#..#.#######.#.######..##..###.....\ +..##.#.#..#.##...#.###.###...######..#..#.#..#....###.#.#....#..........#...##.##.##.#..##..#.#####.\ +###.###.#..#.##..##.#..#..##.....##.....#..#######.#..#.#.#.####.###..###.#.#..#.##.##.####.###.####\ +#.#.#..#....########.#..#..#...##..#.##..#.#..##..####...##.....#.##.#.#...########..#.###.#..#.#.##\ +.##.....#...#.#...##.##....###...##..#.####...#..#.#..#..#.##..#.###.##.####.##..####.....##.#.....#\ +....####.#.##.#.##.#..##.#.######.##.####..#...####.#..###.#.#..#..##.#.#.....##.#####.#.####...#.#.\ +#..#####.#####.....##....######..##....#..#.#.###.#####.....##.##.####.#...##...#.##.#.#####.##.#...\ +##.####..###.#....#...#.#.#.#.###.#####.#.####..####...####......##..#..#..#.#.##...########....#...\ +.###.#.#.#.#..####.##.#..######..#.#.###.....#.#......#.#.#.#..####.##...##.#####.#.##..##..#..#.#..\ +.....###...#...#.####.###.#.#.#.#.....#....#.####.###.##.##.##.#######......#.####......#....##.....\ +##..#..#.#.##..#...#..##.##.##..###.#....##.##....####.#.##.###....#.##.#.#.##...##.###...#..#..####\ +...#.#..##..##.#...##.##...#.#......#.#.##..###....####.##...#.#.###.#..#..#.####..##..##..#####.###\ +.##.##..##########.##...#.##.####.#.#######.##.#.##.##..#...##....########.###..##.##.##.#..##.#.#.#\ +#####.#....#.##..#.....#......##.##..#.##.###..##.......###..##.#.###.##.###....####.#..#.###..#.#.#\ +.#...#..#.##....##....#...####....#...#..#...####...########.###.#..##.#.#.##..###..#.#.###.....##.#\ +##..##.....###......#..###.##.####.##.####.#.#....#..#...#..#.#..#.###.#...#...#..##.##...#..#######\ +.....##..###..##...#####.#.#.....###.#.#..####...#.#.#..#..####..##.#..###.####.#....##..###....#..#\ +#.#.##.#....#.#####.#....##...#...##...##....#.#.......#....#..#...###.###.#.####..####....#.##.#.#.\ +..##...##..###.#.#.##.#..#....#.#.....##.###.#.###.###.....#...#.#..#######.#####..#.###...##......#\ +#......###..#....#.#..#.###.##.#...##..###.####.#.#....#.##..#.###..##.#..#####..##.###.....#..###..\ +##.#.##..##.###.#..##.....#.##.....###....##.####.######.#...#..###....#.#...#.##.....###....#..#.#.\ +.##.#.#.#.##..#.#.#..##..#.###.####....#..###.######..####.#.....###.##..#...###.#..######.##.#.##..\ +...##.####.#..##.#####.##.#...##..#..#...#.#.#.#####...#....#..###...#..#....#.#.##.#.######.#..####\ +..#.#.#.#...#.######.#.....#..#.#..###....#.#.########...#....#.#.##..#...##...#.#..#.#.###....##...\ +#####..#..##..#..##..#..#.#.##.#....#####.####.##.#.###..##..##....#.....#.#####.#...#.#####.##.#.#.\ +#.#..#####...####.###.###.....####.###.....##...##...#..#..#######.#.##....##..####.....##...#..#..#\ +#.#.###.#.#..##..#....#.#...#.#.##.##..#.##.....##...#.#..##.......##.#.###..#####.#.##....#.##.....\ +...#.......#....#.#.####.#.###.###..#....#..##.#..####........#.##..#...#.#...###.#..#.#.#...#...#..\ +...##.#####.##.#.###.##.##.#.##..##.#.#.#.#.#.##.#..##...##.#.#..#..##.##.#####.#.###...#####..#..#.\ +#######.#..#..#....##.#.#..####.#..#..###...#..#.......###.#.#.####....#.###...#.#.###.#.#.#.#..###.\ +..##.##.#.##.###....###.##.#.###.#...#....#.####..###..###.#.#..#...##.#.#.#..##.###..###.#.##...###\ +######..######..##..##.#.#.##.##.#..##..#.#.#.##..#.#...#...#.#.#..######.#..#.#.######..#......##.#\ +#.#####.....#.......#########..###.##...#...##.#.#..#...#####...#...#..#.###.#..#.#...###.#.#.#...#.\ +#....##....###...##.##.#...##.........##.#.#..#.#.##.#.######.#####..#..###.###.#...#.#.##.######...\ +#.#...###.#.###.##.#.######.#######.###.##..#.#.#...######.##.####.##..#.#.#.#......##..##.........#\ +..###..##....#.....##...#.#.###.#.#.....##.#...###.####.#...#...##..##.#.#.####..###...######....#.#\ +..###.#.##.####.#..#.##....##..#####....#..##.##.#..#######...#.####...##.#.#.##.........#....#....#\ +.##.#...#.####..#.#...#.##..######.##..##.#.###.##..###.###....##..#.##.##..##.#...###.##.##.###....\ +#...###.###.#..#....#.......#..#.....###..#.###.##.##....#.####.#.####.##..##..#..#.....#....##.#.#.\ +.##.#..#..#.##.......#.####.#######.....#.##.##.#.....#.#..#....######.#..###.##.##.....#.####..##.#\ +###..#.###.#..####.....##....#..####....#.##.##..#...######.#########...#.#....##...###.#..#.##...#.\ +#..###..##..#.#.##.###.#.#.##...###.#...##.##..#.###....###..#.#...#.###..######.#..#.###..#..#..#.#\ +.#........##.#.###..###.#.#.##.....##.##.#.#...##..#.##....###..#.#.#.#.##....#.##..#.#...###...#...\ +####.####..#....#.#.#..#..##.......##.####...###.##..#.#.##.#..##..######.......##.#.##..#...#.....#\ +..#..#..###..##.##..######.#..###..###.#.##..##.#..#####.#.#.#.##..#.##..##.##......####.#..........\ +...##.##..###.#...###....#.#.#.#.....#.##.....##...#...#......####...##.##....##.#..#.####.#..###.#.\ +..#.....####.#.###.#####..#..###..#..#.#...#####...###.###....#.###..#...#..#..#.#..#.##..##.#.#....\ +..##.#####...###.###.........#....##.####.##..#.#..#.#...#...##.##.##..#.#.##.########......#####...\ +...###.#.#..#...#.###.###.......##.###.#..#.##########...#..#.#.#.##.#.###...######..#.#...###.##...\ +.#.#.#######.#..##.##..##...#...####...#..#####.#..##...###.#.#...#.##...#......#..##.####..#.....##\ +.##.##.#.#......#######..###.....##.#.##..###......#....####...#.###.#.##.#........#..#....##.....##\ +#...#.###.#.##...##.####....#...#.###..#.#.....#.#....#.#.#.##...#.#..#####.#.#..#..#..#....#...####\ +.....##...###......#####..##.##.##...##.#.#####..##...#.#.#.#.###...###.##.####..#.#..#.#..#.####.##\ +#..#..##.#.##.#.##.#.#.#..###....###.##.#.##.#...#.#..#...#....###.#..#.#.######.#...####..#..##.#.#\ +#..#.#..#...###.#..##.#...#...##.#......#...#..#..####..##.....#.###...#.#..#.#....#.#####.##.###...\ +###....#.#..#.#..###..#.##......#...#..#..##.#..###..##..#..#.####..#...########..##.#.##.#.#.#...#.\ +.#.#.##.##.###..#...#.#....#..#.##..#.#.#.#.##.##.#####...#........####..###..####.#####..#.##.#.##. +""".utf8 + +let on = UInt8(ascii: "#") +let off = UInt8(ascii: ".") + +func step(input: [UInt8]) -> [UInt8] { + assert(input.count == 100 * 100) + var result: [UInt8] = [] + result.reserveCapacity(input.count) + + func isOn(_ x: Int, _ y: Int) -> Bool { + return input[x + y * 100] == on + } + + for y in 0..<100 { + for x in 0..<100 { + var onCount = 0 + for i in -1...1 where (0..<100).contains(i+y) { + for j in -1...1 where (0..<100).contains(x+j) && !(i == 0 && j == 0) { + if isOn(x + j, y + i) { + onCount += 1 + } + } + } + + + if (x, y) == (0, 0) || (x, y) == (0, 99) || (x, y) == (99, 0) || (x, y) == (99, 99) { + result.append(on) + } else if isOn(x, y) { + result.append((onCount == 2 || onCount == 3) ? on : off) + } else { + result.append(onCount == 3 ? on : off) + } + } + } + + return result +} + +var current = Array(input) +current[0] = on +current[99] = on +current[99 * 100 + 0] = on +current[99 * 100 + 99] = on + +for _ in 0..<100 { + current = step(input: current) +} + +let count = current.lazy.filter { $0 == on }.count + +print("\(count) lights on") diff --git a/2015/Day2.playground/Contents.swift b/2015/Day2.playground/Contents.swift new file mode 100644 index 0000000..4759868 --- /dev/null +++ b/2015/Day2.playground/Contents.swift @@ -0,0 +1,1049 @@ + +let input = """ +29x13x26 +11x11x14 +27x2x5 +6x10x13 +15x19x10 +26x29x15 +8x23x6 +17x8x26 +20x28x3 +23x12x24 +11x17x3 +19x23x28 +25x2x25 +1x15x3 +25x14x4 +23x10x23 +29x19x7 +17x10x13 +26x30x4 +16x7x16 +7x5x27 +8x23x6 +2x20x2 +18x4x24 +30x2x26 +6x14x23 +10x23x9 +29x29x22 +1x21x14 +22x10x13 +10x12x10 +20x13x11 +12x2x14 +2x16x29 +27x18x26 +6x12x20 +18x17x8 +14x25x1 +30x15x22 +17x18x7 +28x23x24 +15x12x25 +14x7x20 +29x23x8 +24x5x22 +6x22x8 +1x15x26 +14x5x1 +24x28x28 +17x23x23 +4x15x7 +23x8x11 +6x15x1 +23x18x13 +17x1x26 +23x13x17 +2x18x8 +22x22x1 +10x22x6 +28x29x20 +22x21x25 +14x8x23 +12x30x14 +8x7x5 +3x30x15 +4x3x29 +25x18x3 +16x7x16 +4x3x8 +9x16x30 +20x28x3 +28x24x6 +4x18x2 +23x18x5 +22x4x30 +15x30x9 +7x12x12 +3x22x29 +12x1x9 +9x2x25 +17x11x10 +25x24x7 +7x27x26 +26x4x12 +29x2x26 +19x24x12 +23x23x3 +26x28x16 +18x4x16 +25x30x18 +29x19x19 +16x3x27 +29x25x29 +18x19x5 +14x21x30 +19x13x26 +19x10x15 +9x4x7 +18x6x6 +24x25x29 +9x12x27 +15x3x22 +30x17x21 +18x19x28 +9x11x12 +8x28x22 +11x3x4 +28x17x20 +24x18x15 +11x12x13 +6x19x24 +28x4x5 +28x22x23 +13x29x2 +9x16x15 +29x28x1 +10x18x30 +19x11x12 +26x28x25 +23x17x13 +25x1x21 +17x1x27 +17x27x28 +28x13x15 +14x13x25 +11x29x7 +22x29x5 +13x6x14 +23x18x13 +25x7x17 +18x9x20 +21x11x2 +28x11x13 +13x25x1 +19x29x25 +16x29x4 +10x21x10 +7x25x17 +5x9x3 +1x15x6 +8x27x29 +23x6x30 +22x22x29 +6x20x30 +26x25x29 +10x19x19 +20x30x9 +5x30x24 +17x10x27 +30x14x30 +8x17x4 +7x18x6 +3x5x4 +24x17x15 +14x20x17 +22x27x15 +18x14x15 +23x9x11 +21x16x29 +7x18x21 +9x3x29 +10x13x4 +2x30x4 +23x20x4 +8x22x21 +29x28x4 +13x16x25 +21x9x11 +7x26x26 +13x23x30 +19x7x10 +9x23x21 +21x9x17 +9x21x15 +20x29x22 +23x13x15 +19x25x2 +12x11x30 +20x21x6 +21x6x17 +24x26x9 +29x21x29 +29x26x16 +6x16x1 +2x12x6 +6x7x20 +7x2x22 +6x22x4 +13x11x27 +25x27x14 +11x8x6 +26x11x14 +30x3x29 +27x21x20 +15x16x26 +6x22x10 +11x9x25 +23x13x6 +13x9x3 +30x22x13 +29x23x14 +25x19x6 +7x29x11 +19x18x5 +29x25x13 +25x24x27 +1x9x12 +22x9x17 +14x12x28 +19x21x17 +13x25x17 +14x25x12 +4x14x30 +7x15x28 +3x6x25 +6x2x16 +15x19x11 +17x30x20 +20x23x7 +26x21x6 +26x29x24 +2x4x30 +4x22x18 +13x3x28 +27x6x21 +5x3x27 +12x7x11 +28x11x9 +12x9x2 +1x22x20 +15x13x28 +14x19x16 +28x20x3 +20x4x9 +26x7x26 +18x19x25 +7x1x13 +20x23x29 +27x26x8 +11x15x15 +10x21x23 +29x2x11 +21x28x20 +3x18x23 +26x17x17 +14x26x17 +20x7x17 +18x12x8 +4x8x8 +8x15x23 +24x29x5 +1x25x8 +1x28x17 +16x18x13 +29x24x22 +13x16x10 +14x7x16 +15x11x29 +12x15x19 +17x6x28 +4x3x9 +15x16x8 +29x27x11 +2x24x20 +4x21x3 +29x24x27 +18x22x22 +7x8x18 +20x7x8 +19x9x2 +20x17x2 +2x29x10 +19x25x1 +28x9x3 +29x27x20 +7x21x7 +10x4x22 +26x8x5 +26x14x1 +5x27x9 +2x18x3 +3x27x17 +30x17x23 +30x11x20 +4x6x7 +6x29x27 +30x16x20 +24x30x28 +19x20x26 +18x1x25 +26x12x12 +19x15x29 +16x21x24 +23x13x26 +25x16x10 +8x9x18 +24x14x1 +24x15x21 +19x9x14 +8x23x11 +22x2x16 +29x9x26 +3x16x25 +15x20x30 +3x11x12 +15x2x3 +13x7x4 +2x7x27 +9x26x11 +30x24x19 +28x17x21 +10x8x2 +11x15x26 +10x12x20 +24x24x27 +25x26x16 +13x4x20 +25x13x11 +12x22x3 +20x7x1 +12x18x6 +26x8x20 +14x2x7 +23x12x1 +26x24x24 +27x26x23 +26x17x5 +17x24x2 +26x5x6 +23x5x1 +5x18x30 +24x21x19 +5x28x11 +21x20x14 +25x4x22 +26x24x11 +7x5x8 +13x1x30 +5x1x6 +14x5x2 +8x11x7 +13x20x1 +17x30x14 +29x22x10 +12x26x3 +27x17x3 +26x27x4 +5x26x17 +22x11x19 +8x26x3 +24x19x22 +7x1x4 +6x27x30 +4x28x14 +16x14x18 +4x5x20 +19x25x4 +15x15x1 +10x14x14 +16x18x24 +21x27x15 +5x5x10 +1x7x13 +16x2x8 +13x15x11 +3x25x10 +20x29x8 +12x3x2 +10x13x12 +25x27x1 +11x30x19 +7x19x13 +27x6x18 +16x21x19 +21x29x5 +16x23x12 +29x19x15 +5x5x10 +27x15x1 +13x16x22 +29x19x5 +8x12x9 +3x18x5 +13x25x3 +5x9x21 +10x20x16 +9x9x11 +23x21x1 +22x2x15 +27x8x13 +23x7x3 +26x30x15 +29x15x16 +16x27x13 +2x18x9 +10x27x8 +20x9x25 +10x2x17 +16x13x13 +21x26x1 +27x26x24 +9x30x16 +19x17x28 +25x15x1 +10x26x6 +10x11x11 +5x26x25 +30x4x15 +9x8x23 +14x25x7 +8x28x8 +28x18x24 +4x4x25 +16x25x11 +17x27x8 +15x16x9 +24x13x21 +17x3x27 +27x5x26 +8x27x12 +29x2x8 +24x23x30 +1x30x21 +6x18x20 +13x14x12 +25x30x23 +24x6x24 +12x7x21 +11x6x8 +8x30x30 +26x3x12 +28x6x5 +18x7x1 +7x6x20 +14x16x18 +11x22x15 +4x20x10 +19x24x19 +8x24x11 +4x9x10 +6x6x22 +10x9x29 +1x5x28 +19x25x29 +20x30x3 +15x13x13 +9x9x24 +20x14x29 +26x24x13 +2x25x8 +10x26x2 +12x19x12 +18x6x20 +4x5x14 +26x27x10 +16x26x20 +3x21x15 +2x26x18 +14x11x17 +26x26x25 +10x1x11 +17x19x19 +27x28x26 +9x2x10 +19x30x15 +23x30x14 +15x3x20 +2x14x22 +21x18x8 +22x4x29 +19x6x29 +9x26x29 +16x10x9 +22x12x22 +13x28x14 +25x14x28 +28x3x30 +10x17x1 +10x27x22 +10x23x19 +14x25x9 +11x24x8 +30x25x10 +22x13x28 +2x7x6 +11x20x8 +9x22x14 +19x16x9 +11x24x4 +11x17x2 +6x4x10 +26x10x10 +12x14x5 +27x10x3 +15x3x6 +11x7x19 +22x10x12 +21x26x10 +13x20x3 +27x8x8 +1x24x23 +24x9x22 +23x17x23 +3x28x19 +2x20x28 +23x17x24 +26x1x4 +4x1x12 +5x6x16 +13x22x13 +25x21x21 +20x21x12 +9x24x25 +17x16x12 +12x28x9 +18x16x27 +29x12x2 +30x12x15 +24x11x10 +4x9x22 +4x24x5 +19x11x5 +6x25x6 +1x20x17 +22x8x21 +11x26x4 +16x19x3 +8x12x8 +13x2x18 +10x5x11 +8x12x17 +21x2x5 +26x17x26 +23x18x17 +28x11x14 +1x4x27 +29x5x28 +5x9x10 +5x7x25 +20x15x27 +15x11x17 +12x14x1 +29x14x4 +18x14x18 +14x25x24 +26x14x18 +13x8x11 +30x1x23 +3x4x12 +12x24x9 +8x6x16 +14x15x30 +12x30x8 +22x11x18 +16x30x28 +17x18x4 +13x14x23 +2x28x8 +3x28x30 +29x30x8 +4x6x26 +6x30x17 +11x30x30 +19x4x3 +12x15x20 +22x28x4 +26x30x2 +6x12x7 +1x10x5 +25x29x7 +17x9x18 +16x21x29 +21x14x7 +15x16x11 +26x6x15 +8x24x7 +2x20x4 +2x9x3 +19x8x13 +18x7x22 +27x14x17 +2x13x8 +18x15x26 +15x27x27 +18x11x15 +1x29x20 +21x12x11 +20x2x15 +28x23x9 +1x1x17 +7x23x9 +30x9x27 +9x16x18 +15x24x28 +30x11x18 +29x26x10 +9x5x25 +2x1x19 +14x3x14 +6x3x6 +30x15x20 +20x17x27 +28x10x9 +14x24x28 +17x11x6 +12x3x6 +8x8x15 +23x14x21 +11x21x7 +5x13x30 +4x29x25 +30x28x24 +18x4x9 +3x15x6 +13x9x19 +30x14x7 +7x9x9 +17x11x26 +24x26x13 +16x21x16 +27x17x25 +2x21x11 +9x11x27 +3x3x7 +13x8x14 +20x20x26 +13x29x22 +30x11x1 +7x10x19 +27x5x9 +23x17x15 +21x6x13 +24x15x16 +18x4x14 +18x16x6 +22x11x18 +14x2x5 +15x3x7 +10x20x29 +16x1x10 +30x23x1 +10x15x11 +17x14x5 +22x8x13 +7x11x28 +26x17x3 +2x23x2 +28x13x19 +18x12x28 +22x23x16 +14x12x1 +20x8x19 +17x19x13 +29x2x12 +2x26x27 +29x16x4 +13x8x18 +16x15x30 +23x16x2 +28x8x27 +21x8x23 +13x20x26 +19x6x17 +17x30x15 +7x4x30 +2x13x30 +18x7x19 +4x13x27 +8x6x5 +18x20x25 +2x3x30 +23x27x13 +22x30x4 +23x25x25 +23x16x19 +25x3x1 +5x6x15 +11x29x12 +25x24x7 +16x7x20 +20x3x2 +12x27x15 +16x10x12 +1x3x14 +22x1x26 +2x24x18 +11x29x16 +15x2x9 +10x1x24 +21x8x11 +30x11x23 +6x30x21 +13x27x29 +14x6x5 +18x29x19 +12x4x28 +29x3x14 +10x30x28 +5x7x15 +14x1x10 +9x25x14 +7x24x18 +28x17x21 +18x13x25 +26x15x1 +21x1x19 +12x16x21 +4x6x13 +7x15x26 +17x19x5 +12x28x2 +1x20x19 +27x7x5 +17x26x8 +12x15x19 +5x23x10 +8x2x8 +16x13x12 +14x27x1 +26x29x3 +24x16x14 +14x13x13 +7x22x23 +2x9x30 +4x27x8 +26x27x15 +23x1x6 +25x29x18 +5x18x1 +20x8x20 +5x10x25 +30x25x15 +7x22x25 +28x26x17 +29x4x1 +21x11x27 +20x9x8 +25x22x12 +2x11x11 +23x2x16 +23x27x20 +2x13x28 +27x2x24 +11x1x17 +12x4x27 +16x20x22 +30x12x10 +5x15x4 +5x2x27 +12x4x25 +1x16x4 +27x4x4 +21x16x3 +27x26x3 +24x6x6 +24x12x12 +20x20x25 +8x29x2 +21x4x5 +2x4x8 +4x13x19 +3x20x10 +12x15x16 +6x5x4 +12x16x20 +22x19x17 +8x17x22 +25x16x15 +7x1x19 +10x1x7 +23x23x5 +28x6x12 +2x25x12 +10x27x12 +24x27x19 +14x14x20 +4x1x5 +16x27x29 +20x20x24 +28x24x30 +6x15x15 +9x15x30 +23x26x3 +17x24x21 +22x25x25 +18x29x10 +20x25x1 +24x11x16 +20x7x21 +20x7x9 +7x26x2 +5x18x1 +16x26x28 +4x10x18 +27x30x21 +26x9x9 +8x16x14 +6x27x8 +28x9x20 +13x13x4 +9x18x16 +18x15x18 +22x19x14 +14x10x17 +25x29x11 +1x18x19 +8x11x26 +18x6x14 +30x24x13 +27x1x27 +15x9x3 +2x29x17 +2x26x21 +22x9x9 +20x20x20 +22x28x2 +26x5x16 +11x3x14 +21x16x16 +18x26x7 +18x30x6 +7x11x12 +15x10x2 +27x2x16 +27x30x24 +28x14x24 +7x4x8 +6x28x15 +13x19x1 +22x26x30 +7x30x24 +2x17x21 +19x26x2 +19x24x15 +14x23x2 +21x27x15 +30x15x14 +21x29x5 +23x30x2 +4x1x2 +15x5x13 +21x2x30 +20x7x16 +1x21x25 +2x25x1 +12x29x5 +28x13x16 +26x3x12 +29x20x23 +28x12x20 +4x30x8 +16x15x16 +6x16x29 +2x28x13 +24x25x2 +26x15x22 +17x20x11 +18x12x7 +19x1x18 +8x27x13 +22x16x8 +19x26x17 +13x11x10 +22x12x3 +13x12x14 +29x17x9 +6x14x10 +14x20x10 +8x26x9 +25x13x22 +3x30x25 +14x28x1 +30x29x12 +3x17x15 +3x24x14 +28x24x22 +16x6x1 +20x25x14 +17x17x13 +6x19x27 +10x15x20 +8x23x20 +7x29x21 +18x9x25 +10x5x22 +2x27x27 +16x18x30 +15x5x12 +26x29x29 +28x11x10 +9x29x28 +24x15x23 +26x9x10 +5x1x25 +22x27x16 +7x29x3 +1x3x5 +8x7x29 +19x21x11 +28x13x30 +17x16x20 +5x10x25 +9x14x15 +15x14x23 +16x4x17 +21x8x2 +9x9x8 +22x22x4 +10x2x27 +12x19x10 +15x29x4 +22x14x7 +29x18x5 +1x7x27 +24x1x15 +23x23x26 +12x17x23 +26x10x24 +8x22x2 +8x1x10 +22x19x12 +2x23x13 +11x27x25 +26x15x27 +27x7x21 +18x9x6 +22x21x22 +7x12x26 +23x21x13 +14x3x8 +5x9x28 +29x29x15 +27x25x23 +12x2x24 +8x2x20 +29x19x4 +12x24x29 +2x27x28 +14x20x9 +28x6x25 +18x29x8 +19x11x30 +15x11x23 +18x7x7 +14x20x14 +26x18x22 +27x25x13 +12x10x30 +30x2x7 +28x10x1 +18x10x30 +22x11x5 +22x16x3 +25x15x9 +5x10x24 +4x28x8 +19x24x18 +3x4x25 +14x4x30 +11x26x3 +12x12x12 +26x7x24 +3x2x14 +1x27x7 +2x2x13 +3x26x26 +12x4x11 +12x17x20 +4x19x30 +5x18x10 +17x6x18 +19x30x20 +11x2x17 +30x13x19 +22x23x7 +17x28x2 +5x17x30 +7x11x4 +21x26x18 +15x28x4 +5x6x27 +12x6x16 +9x17x12 +27x20x5 +14x5x20 +27x14x6 +2x14x21 +4x28x30 +24x5x1 +19x29x29 +11x23x1 +8x16x21 +3x17x19 +10x13x5 +20x21x16 +23x3x6 +27x26x11 +3x2x22 +14x3x5 +10x9x8 +""" + +struct Present { + var l, w, h: Int + + init?(_ array: [Int]) { + guard array.count == 3 else { return nil } + l = array[0] + w = array[1] + h = array[2] + } + + var smallestSideSize: (Int, Int) { + let sides = [l, w, h].sorted() + return (sides[0], sides[1]) + } + + var smallestSide: Int { + let (a, b) = smallestSideSize + return a * b + } + + var area: Int { + 2 * (l * w + w * h + h * l) + smallestSide + } + + var volume: Int { + l * w * h + } + + var ribbonLength: Int { + let (a, b) = smallestSideSize + return volume + 2 * (a + b) + } +} + +input.split(whereSeparator: \.isNewline).map { + $0.split(separator: "x") + .compactMap { Int($0) } +}.compactMap { Present($0) } +.map(\.ribbonLength) +.reduce(0, +) + + + +// step 1: 1586300 + diff --git a/2015/Day2.playground/contents.xcplayground b/2015/Day2.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day2.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day2.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day2.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day2.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day3.playground/Contents.swift b/2015/Day3.playground/Contents.swift new file mode 100644 index 0000000..67b2900 --- /dev/null +++ b/2015/Day3.playground/Contents.swift @@ -0,0 +1,37 @@ +struct House: Hashable { + var x, y: Int + + mutating func move(direction: Character) { + switch direction { + case ">": x += 1 + case "<": x -= 1 + case "^": y -= 1 + case "v": y += 1 + default: break + } + } +} + +var currentSanta = House(x: 0, y: 0) +var currentRobo = currentSanta +var visited: Set = [currentSanta] + +var input = """ +^><^>>>^<^v<<^<><^<^v>^vv<>v>>^^^v<<<^>^<^v<^>^v><<<^>><>v>v^<<^>^<<^^^>v>>v^^>^>vv>>^>>v^>^v>^<^^v>^>^^v^^>v^^v><^><^<<>v^<^<^vv^>>>v^v^>^<>^v<^^vv^>^<>^^<vv<>^>v<^>^v>v^>^v<>^><>>v^v<><>v^v>>>>v^^>^><^^<^>^v^v<>v<<<^<v^^^<^^^>v<^v>>>>>v<^^^^>v<^<>>>>>>v^vvvv^^^v<^v^>v><^>^v<<>>vv^>v>v^^>vv^<^vvv<>><>><><^^^^<^^^<^v>>v>^v^^^>v^^^v>>^v^^<^>>^>^<>>^^<>>^vv>v^<^>>>><><^^v<><<<<^^<>>^<>vv^<^>v^^><^v>^^>v<>^v^<>^vv^>vvv>v>^>^>>^>><>>>^^^^v^<>v^^>^<>v<^^v><^v><>^^^^^v^v>>^^v><<><^^^^><^>v>><<<^v>v^^>^v^<^^v>v<^<<>>^v<<>v<^v^>v^>^v<<v>v>>v>v^^v>^v^>>>><>^>v>^v^>>>>v^<<<>vvv>><^^>^<><^^<^v^v^<^^>^<^v^<<<^^v^v>>><>^^>vv<<^v^<<<<^^>>>v>v<<<>^^>>>v>^>v>vv<<>^<^>^^<^>^v^<>v^><^^^>vv>><^v<^<<<><<^^<><>v>^>^<>>^^v>vv^<^^v>><^vv^<<<>vv^v<^<>v^^>><>^<^v<<<^<<^>>>^^<^^v>v^vvvv>v<>><^>^<<<v^^^v<>v>^^<v>>v>>v^>^<>v><>>>v^>^v<^<><<^>^^^>^><>^><^<>vv<>>v^v>^>^>^<^><>v<><>>>^^^<^v>>^<>>>vv^>vvvv>>><^>v<>^^^>v>>v^v^>^^<<^>^>>v<<><>v^^>v^><<^v^>^^<v><<<^v^<>^<>^>>^<^^<>^v<>v^>>><>^><>>vv>v^<^^^>v>^^>^v<><>>><>><^<>>v>v^^>^^<^^>^>>v>vv^^v<^<^v>><<^>^v>^^^<<>v^<^^v<<<>^^vv<^>vv>^>^<><<>vv<^>v^vv>^^^v><<^vv>^v<>vv^^<^<>^^v^<^vvv>v^^<>^^>^^>^<><<^v>^><^^vvvv<><>^v<>^><>v>><>vv^<<><<>><>v<^>^v>>^^v><<<>>^<^v^^^<^<><><^><<<<^^<>><><>>v><<vvvv^^vv><<^v^vvv><>v><>v<<<^><^^>v^>^^^v^v>><<>^v<>v^v<<<<^^^v^v<<>>>v>>vv>^^<><^v<>>v^>>>>>^>v^v^<^v^v^vvv>vvv^<vv>>v^^vv<^v>>>>vv<>v<>^^vv^v^>>vvv<<v>v>^><<<^>v^>^v^^^><<><<<^^<^^<>^^v<^v>^v<^>^>><>^v^v<<^>^>v><^>^vv^^^v^v^>^<<>>>>>v^<>^>v^vv^><<>>^^<>v^>^vvv^>v^v><>^><<>v>v<^<^><^^vv<<><>>v>>v>>^v<<>^vv<>^vv>v>v>^>^>>><><<>v^<<^v^^<<<>>vv<^<<>v<^^^<<^v^>^v>^^^v^v>>>v>v^v>^>^vv<^^<^<<v^<><<^vvv^^><>vv^v>v>^><<^^^^vvv^><^v<^>^<>>^>>vv^<>>^v>^>v>^<^<^^^<>>>>>>v>^<>^^v^><>><^v^^><>v^v<^<<<<^>^^>vv>><^v^vvv>v^^><^^<^<>>^^v^vv<>v<^<<v>v<>^v^><>v<^v>><<^<^v^>><^<^><>v>>^vv<^v>^>v<^>>^>>v^>^v<^v^v><<><>^><<<><>^<>^^^^v>^>^vvvvv>v>>v><<<^><<^v><^v>>>>^v<^v<<>>^>^<v>><<^>^>^v><><>^><v^><<^v^<^^><^^v^<<^v^^>>^v^<^>v^^<<^^^<><>^>v^v>v^>^v^vv>^^>>>>^^<^>>>^^v<^^v><<<>^>^^>^>^v<<<<>>^<<>>>v>^^<^v<>v<>v^>v^><^<^^>^^vv><>v>^<<<^><^^<^<^^v<^>v^v^^^><^>v^v>>^^v^>>>>><<>^>v>v<>>>v>^^^^>>v^<<^>>><^v^<<>>v><>^v^^><<>>^>^>vv<^<>^vvv^vv^v>^^<<<<<>^v^>^<>v^^<>v^v^<>vv^<^vv>>><<>v^^^>^>^^>>>vvv>^>v>v>>>^>vv^><>^><>v>^^^><><<<>>v^v<^<>^^<>^^<<><>^v<><>>>^vv<^<<^<^v>v<<<<<^^v<^v<><^>v>^v>>^v^><^^^^v<><><>vv^<>vv<^v<^^><^^v^v^<^^<<>v<>v^v<^>vvv><<^v>>v><>>>v<^>>v>^<>><>^v<^^>^<^v<^<<^^v<>>^>^>^v^^v^v>v>v<>v^>v^^>^^>><<>><<^^>><^v<<><<>>>>>>^^^^^<<>^<<^><<^^vvv<<>vv><<>v>v^v>>>>>^<>><^^^><<<<>>v<^>>>^^vvv>v<>>>>v>>^v^vvv<<>vvv<<^^^<>vv^^v<<>^^^>>^<^v^<^^>v^>>^<<^v<v^>>^>v^><^><>^>>>vv>><^^^>vv<<^^vv><^<>^>^^<^<>>^vv^>>^v><>v^>>><<<^^<^>^>v<^>^<^^<>>><^^<>^v^<<>vvv>v^v<<^^^><<^vv^v>v>v<<^v^<<<>^><>v>^vv^v<>vv^>^^<^>^>v^^v><>>^v<^<><><^vv<><<>v^^>^^<><<>^<^<<<>v>><^<<>^>^v^v<^>>^v<^>v<<>^^^<^v>>>^vvvv<vvvv>v<>v^<><>vvv<>^<<>^>>>>v^<^<><^v>v^>>v><>^><^<<>^>^v^>^v>^<>v^<^^>v>^>>>v^v>>>^<>^<>>>>>v>>vv^v<><<<><><<>>vv<^^v<<>v^v<^v<>>^v>>vvv^^v>>v>^>^>v><^>^^<<>^v<^<<<<^>v<^>>v^<^v>^v<<>^>^vvv<^^vv>^vv>vv<>>v>v>v^<<<<<^^v^>v>^<<>v^<<>>^<^>^^<>>>>^<^v<>v^^>^<^^v<^><>>>^v^vv<^v<^><><>><^^>^<^v^<^<>v<<<^v>v^^^<>v^^v^>><>^^<<^^v^<>^<^vv>>><^v>vv<^v<<>v>v^v>^v<^<>v^vvv>^vv<<<<^>>^^>><^v><<^>v^^<<<<<>^v<<^^>v<<<<^>^>^>>^>>>v^<>^^v>>>^vvv<^v<>>>vv>^^><^v>vv^>>v>v^<>^^>^<<^>^^^>>^vv>^^>vvvv<>>^^^^>>>v>v^^>vv>vv^<<>^><^><<>>^>^><^v^>v^<>^>v^^v^>^^>v<<<<^<<^>>v>v^^^<<>>^^v>v<<<<^^^v>^vv^>><>^v<>>>v>vvv^v^^v^>>vv>^>><>^v><^v^><^^>vv>^<^<^>>v>><><>^>^>v>vv>vv>^^>v>v^>^>^v>^^v>^<^v<>>vvv^^>^>vvv^^v<^<^>vv^^<^^^>v>vv<v<^>^v^<^>v<^>^<>vv^><>>^>>^<^><<>^<^>v>v><>>>^<<^><<^v<>>vv<^>>v>v>>>>^^>v<^v^>><<^<>>v><^><<^>^<<>>^^<><^^v>^^>vv>^v>^^v^<^<<>>v^^^<^><^<<><><<>^v>vvv^vvv^^>>^<^><>^<<<<^^<>>>v^<<^^v>><><v>^vv>vv^><>^><<><^^>^>^<><>><^^<><>^>><^v<<<<>>^v>^^vv^v^<><<vv>>v>>^v^<>>vv^<^>^<<>v<<<^vv<^vv^vv<^v^^^v>>v<^^<^^vvv<^^v<>>>^>v^>^^><>vv>v>v<<<^^v<^vv^v>^^^>>>^^<>^^<^vvv>><><<><^><<>^>^^vv>vv^^<^^<<><><v><<>v>vvv<^^^^<^>>><<<^^^<^>vv^^v>>v<vvv^^v^^<^v<^<>^<^v>>^><><>v>>>^^>>v^>><>v<><>>><>>>>><<^vvv<<><><<>^><><<^^v><<^>v>^>^v>v>>^^<><^>vv<^<^v>v<><^<<^><>^^^^^v>><>^>^vvv>v^vv^v^>v><>v^><>v>^^^^><^v^^^>^^><<^^>v>v<^v^^vv^<<<<^>v>v^v><>^><><>^v^<>^v>^v>v^<><^>>v<<^><^vv^<><^<>><>><<^^^^>v<^<^vv<><^vv><<^<v^>>^v>^>v^^v>vvv<v<>^>>vv^>>><>^v^^<^>v<<^<^^v^^v^<vv^><^v<^>>>vv^^^^v>^><^^^<><<^^>v<><><><>vv^><<^>^><^v<^<^v^v<<<<<<><vv>v<^><<><><<>>v>><^>^v>^v^<>v^^^><^^<<<^vv^vv>^v^vvv^^>v^><^<^<^<>^vv^^^>vv^v>>><<<^<>>v>v<^^<>>><><^v^^<<><<<>^<^^v^>v><^<^>^>>^<>^v><>>^vv^>^^<<<^v<>>^v<>vvv<<^^<<>>>>^^<><>^><>^vv^v<^>^v<>v^vv<><^vvv<><<^>>^^><><>^<>^>v^^v^><>>v>><^v>^v<<<>vvv^<^^v^<>^>>v<>^^><>>^><^^vv>><<>><^><>>^vv>vv^v^^v<<^^v^^vv<<^<<><>^<><^<^<>>^vvv>>^<^vv>^vv^>v>^<><^><^<>v^v^^<^<>^^v>>><^v<>v^v<<^>v><>^^<v^>>v>^<>^>^>^<^>v><<><><><<<>^>><^>>>^v<<<^<<>^><<^>>>>>v<^>v>>v^^>v^^><>v^v^vvvvv>>><<>^<v>^>^vv^^<^>>v>vv^v<^<>^v^<^<<><<<^vvv^>^^<<>>>vv<<^<><^v<^<><<^^>vv^v>v^^^>>>>^>vv<v>>^^v^^><>v<<^><^>^>v^v>><^v^>v<<^<^<^<^<>>v^^>><<<>vv<^^>^vv<<<^^v^^>v<<><^<>^^>^v<>v>><^^^vv^>^><>v^^>^v>^<<^v>^>>>>><^^^<>v>v^^<^v^>>v^<^>v^v>>>>^>>vv<>^<^v>v>v^v>^<>^>v<<>^<>>^<>>^<>v^><<>^v>>^^^^<<^v><>^<^>^^v><^^<^^v>v<<^>^>><<^^^vvv<<^vv<^^>v^^vv^<^^<<^^>>^^<v^>>v^^>v<^>^>vv>><v><^<^vv>^^v>^>v<<^vv><^^^^^^><<^>>>^v<>^^v<<<>><<<>^<<v^>^^^<^>^^^v<<>v^><<^^<<^v<<>^v>>vv>><<^v^^>v^v>^^v<><^^^<^^>v>^<>vvv^v^^^>v^^v<^>^^>>^v<><^><^<<^vv^<><<>v^vv^<<<^^>v<<>>>v<>v<><<^v>^^v>^^>v>^>^>v<>><>^>^>^vvvv<^^^^^v>v>><>^>^><>^^>v^^<<><^><<<<>v>^^>^v<<<>vvv>>v<^v>>v>v^<<<>^>^>^<>v<^^vv><^v<<^vv<^<<^^vv^^>vv<^>v>^^<^>v<<^^<^>^^^v^^>>v^vv^<^v>^<>^<^>>^<^v<>v><^^<><>^>v<^<^vv>><^v>^<>^^>^<><<>^<>><<>vvv^<<^^>>v<^>>vv>^v^^^v<>v<>><>^vv^>vv^ +""" + +var santasTurn = true + +for direction in input { + if santasTurn { + currentSanta.move(direction: direction) + visited.insert(currentSanta) + } else { + currentRobo.move(direction: direction) + visited.insert(currentRobo) + } + santasTurn.toggle() +} + +visited.count + diff --git a/2015/Day3.playground/contents.xcplayground b/2015/Day3.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day3.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day3.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day3.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day3.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day4.playground/Contents.swift b/2015/Day4.playground/Contents.swift new file mode 100644 index 0000000..eb5a195 --- /dev/null +++ b/2015/Day4.playground/Contents.swift @@ -0,0 +1,24 @@ +import CryptoKit +import Foundation + +func md5(_ string: String) -> String { + let digest = Insecure.MD5.hash(data: Data(string.utf8)) + digest.withUnsafeBytes { ptr in + ptr[0] + ptr[1] + } + digest.pref + return digest.reduce("") { + $0 + String($1, radix: 16) + } +} + +let key = "abcdef" + +var iterator = (0...).lazy.map { ($0, md5("\(key)\($0)")) } +.filter { $0.1.hasPrefix("00000" ) } +.makeIterator() + +iterator.next() + + + diff --git a/2015/Day4.playground/contents.xcplayground b/2015/Day4.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day4.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day4.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day4.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day4.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day5.playground/Contents.swift b/2015/Day5.playground/Contents.swift new file mode 100644 index 0000000..51bd1b8 --- /dev/null +++ b/2015/Day5.playground/Contents.swift @@ -0,0 +1,1122 @@ +import Foundation + +extension Character { + var isVowel: Bool { + return "aeiou".contains(self) + } +} +extension String { + var vowelCount: Int { + lazy.filter { $0.isVowel }.count + } + + var containsDuplicate: Bool { + let last = index(before: endIndex) + var current = startIndex + + while current < last { + let next = index(after: current) + if self[current] == self[next] { + print(self[current...next]) + return true + } + + current = next + } + + return false + } + + var containsForbidden: Bool { + let forbidden = ["ab", "cd", "pq", "xy"] + return forbidden.reduce(false) { + $0 || self.range(of: $1) != nil + } + } + + var isNice: Bool { + vowelCount >= 3 && containsDuplicate && !containsForbidden + } +} + + +"aei".vowelCount >= 3 +"xazegov".vowelCount >= 3 +"aeiouaeiouaeiou".vowelCount >= 3 + +"abcdde".containsDuplicate +"aabbccdd".containsDuplicate + +"aabbccdd".containsForbidden + +"ugknbfddgicrmopn".isNice + +let input = """ +sszojmmrrkwuftyv +isaljhemltsdzlum +fujcyucsrxgatisb +qiqqlmcgnhzparyg +oijbmduquhfactbc +jqzuvtggpdqcekgk +zwqadogmpjmmxijf +uilzxjythsqhwndh +gtssqejjknzkkpvw +wrggegukhhatygfi +vhtcgqzerxonhsye +tedlwzdjfppbmtdx +iuvrelxiapllaxbg +feybgiimfthtplui +qxmmcnirvkzfrjwd +vfarmltinsriqxpu +oanqfyqirkraesfq +xilodxfuxphuiiii +yukhnchvjkfwcbiq +bdaibcbzeuxqplop +ivegnnpbiyxqsion +ybahkbzpditgwdgt +dmebdomwabxgtctu +ibtvimgfaeonknoh +jsqraroxudetmfyw +dqdbcwtpintfcvuz +tiyphjunlxddenpj +fgqwjgntxagidhah +nwenhxmakxqkeehg +zdoheaxqpcnlhnen +tfetfqojqcdzlpbm +qpnxkuldeiituggg +xwttlbdwxohahwar +hjkwzadmtrkegzye +koksqrqcfwcaxeof +wulwmrptktliyxeq +gyufbedqhhyqgqzj +txpunzodohikzlmj +jloqfuejfkemcrvu +amnflshcheuddqtc +pdvcsduggcogbiia +yrioavgfmeafjpcz +uyhbtmbutozzqfvq +mwhgfwsgyuwcdzik +auqylgxhmullxpaa +lgelzivplaeoivzh +uyvcepielfcmswoa +qhirixgwkkccuzlp +zoonniyosmkeejfg +iayfetpixkedyana +ictqeyzyqswdskiy +ejsgqteafvmorwxe +lhaiqrlqqwfbrqdx +ydjyboqwhfpqfydc +dwhttezyanrnbybv +edgzkqeqkyojowvr +rmjfdwsqamjqehdq +ozminkgnkwqctrxz +bztjhxpjthchhfcd +vrtioawyxkivrpiq +dpbcsznkpkaaclyy +vpoypksymdwttpvz +hhdlruwclartkyap +bqkrcbrksbzcggbo +jerbbbnxlwfvlaiw +dwkasufidwjrjfbf +kkfxtjhbnmqbmfwf +vmnfziwqxmioukmj +rqxvcultipkecdtu +fhmfdibhtjzkiqsd +hdpjbuzzbyafqrpd +emszboysjuvwwvts +msyigmwcuybfiooq +druyksfnbluvnwoh +fvgstvynnfbvxhsx +bmzalvducnqtuune +lzwkzfzttsvpllei +olmplpvjamynfyfd +padcwfkhystsvyfb +wjhbvxkwtbfqdilb +hruaqjwphonnterf +bufjobjtvxtzjpmj +oiedrjvmlbtwyyuy +sgiemafwfztwsyju +nsoqqfudrtwszyqf +vonbxquiiwxnazyl +yvnmjxtptujwqudn +rrnybqhvrcgwvrkq +taktoxzgotzxntfu +quffzywzpxyaepxa +rfvjebfiddcfgmwv +iaeozntougqwnzoh +scdqyrhoqmljhoil +bfmqticltmfhxwld +brbuktbyqlyfpsdl +oidnyhjkeqenjlhd +kujsaiqojopvrygg +vebzobmdbzvjnjtk +uunoygzqjopwgmbg +piljqxgicjzgifso +ikgptwcjzywswqnw +pujqsixoisvhdvwi +trtuxbgigogfsbbk +mplstsqclhhdyaqk +gzcwflvmstogdpvo +tfjywbkmimyyqcjd +gijutvhruqcsiznq +ibxkhjvzzxgavkha +btnxeqvznkxjsgmq +tjgofgauxaelmjoq +sokshvyhlkxerjrv +ltogbivktqmtezta +uduwytzvqvfluyuf +msuckpthtgzhdxan +fqmcglidvhvpirzr +gwztkqpcwnutvfga +bsjfgsrntdhlpqbx +xloczbqybxmiopwt +orvevzyjliomkkgu +mzjbhmfjjvaziget +tlsdxuhwdmghdyjb +atoecyjhwmznaewi +pyxpyvvipbqibiox +ajbfmpqqobfsmesj +siknbzefjblnohgd +eqfhgewbblwdfkmc +opylbscrotckkrbk +lbwxbofgjkzdxkle +ceixfjstaptdomvm +hnkrqxifjmmjktie +aqykzeuzvvetoygd +fouahjimfcisxima +prkzhutbqsyrhjzx +qqwliakathnsbzne +sayhgqtlcqqidqhj +ygduolbysehdudra +zricvxhdzznuxuce +ucvzakslykpgsixd +udirhgcttmyspgsb +yuwzppjzfsjhhdzi +gtqergjiuwookwre +xvxexbjyjkxovvwf +mlpaqhnnkqxrmwmm +ezuqbrjozwuqafhb +mcarusdthcbsonoq +weeguqeheeiigrue +pngtfugozxofaqxv +copphvbjcmfspenv +jiyahihykjjkdaya +gdqnmesvptuyrfwp +vbdscfywqmfxbohh +crtrfuxyjypzubrg +seihvevtxywxhflp +fvvpmgttnapklwou +qmqaqsajmqwhetpk +zetxvrgjmblxvakr +kpvwblrizaabmnhz +mwpvvzaaicntrkcp +clqyjiegtdsswqfm +ymrcnqgcpldgfwtm +nzyqpdenetncgnwq +cmkzevgacnmdkqro +kzfdsnamjqbeirhi +kpxrvgvvxapqlued +rzskbnfobevzrtqu +vjoahbfwtydugzap +ykbbldkoijlvicbl +mfdmroiztsgjlasb +quoigfyxwtwprmdr +ekxjqafwudgwfqjm +obtvyjkiycxfcdpb +lhoihfnbuqelthof +eydwzitgxryktddt +rxsihfybacnpoyny +bsncccxlplqgygtw +rvmlaudsifnzhcqh +huxwsyjyebckcsnn +gtuqzyihwhqvjtes +zreeyomtngvztveq +nwddzjingsarhkxb +nuqxqtctpoldrlsh +wkvnrwqgjooovhpf +kwgueyiyffudtbyg +tpkzapnjxefqnmew +ludwccvkihagvxal +lfdtzhfadvabghna +njqmlsnrkcfhtvbb +cajzbqleghhnlgap +vmitdcozzvqvzatp +eelzefwqwjiywbcz +uyztcuptfqvymjpi +aorhnrpkjqqtgnfo +lfrxfdrduoeqmwwp +vszpjvbctblplinh +zexhadgpqfifcqrz +ueirfnshekpemqua +qfremlntihbwabtb +nwznunammfexltjc +zkyieokaaogjehwt +vlrxgkpclzeslqkq +xrqrwfsuacywczhs +olghlnfjdiwgdbqc +difnlxnedpqcsrdf +dgpuhiisybjpidsj +vlwmwrikmitmoxbt +sazpcmcnviynoktm +pratafauetiknhln +ilgteekhzwlsfwcn +ywvwhrwhkaubvkbl +qlaxivzwxyhvrxcf +hbtlwjdriizqvjfb +nrmsononytuwslsa +mpxqgdthpoipyhjc +mcdiwmiqeidwcglk +vfbaeavmjjemfrmo +qzcbzmisnynzibrc +shzmpgxhehhcejhb +wirtjadsqzydtyxd +qjlrnjfokkqvnpue +dxawdvjntlbxtuqc +wttfmnrievfestog +eamjfvsjhvzzaobg +pbvfcwzjgxahlrag +omvmjkqqnobvnzkn +lcwmeibxhhlxnkzv +uiaeroqfbvlazegs +twniyldyuonfyzqw +wgjkmsbwgfotdabi +hnomamxoxvrzvtew +ycrcfavikkrxxfgw +isieyodknagzhaxy +mgzdqwikzullzyco +mumezgtxjrrejtrs +nwmwjcgrqiwgfqel +wjgxmebfmyjnxyyp +durpspyljdykvzxf +zuslbrpooyetgafh +kuzrhcjwbdouhyme +wyxuvbciodscbvfm +kbnpvuqwmxwfqtqe +zddzercqogdpxmft +sigrdchxtgavzzjh +lznjolnorbuddgcs +ycnqabxlcajagwbt +bnaudeaexahdgxsj +rlnykxvoctfwanms +jngyetkoplrstfzt +tdpxknwacksotdub +yutqgssfoptvizgr +lzmqnxeqjfnsxmsa +iqpgfsfmukovsdgu +qywreehbidowtjyz +iozamtgusdctvnkw +ielmujhtmynlwcfd +hzxnhtbnmmejlkyf +ftbslbzmiqkzebtd +bcwdqgiiizmohack +dqhfkzeddjzbdlxu +mxopokqffisxosci +vciatxhtuechbylk +khtkhcvelidjdena +blatarwzfqcapkdt +elamngegnczctcck +xeicefdbwrxhuxuf +sawvdhjoeahlgcdr +kmdcimzsfkdfpnir +axjayzqlosrduajb +mfhzreuzzumvoggr +iqlbkbhrkptquldb +xcvztvlshiefuhgb +pkvwyqmyoazocrio +ajsxkdnerbmhyxaj +tudibgsbnpnizvsi +cxuiydkgdccrqvkh +cyztpjesdzmbcpot +nnazphxpanegwitx +uphymczbmjalmsct +yyxiwnlrogyzwqmg +gmqwnahjvvdyhnfa +utolskxpuoheugyl +mseszdhyzoyavepd +ycqknvbuvcjfgmlc +sknrxhxbfpvpeorn +zqxqjetooqcodwml +sesylkpvbndrdhsy +fryuxvjnsvnjrxlw +mfxusewqurscujnu +mbitdjjtgzchvkfv +ozwlyxtaalxofovd +wdqcduaykxbunpie +rlnhykxiraileysk +wgoqfrygttlamobg +kflxzgxvcblkpsbz +tmkisflhativzhde +owsdrfgkaamogjzd +gaupjkvkzavhfnes +wknkurddcknbdleg +lltviwincmbtduap +qwzvspgbcksyzzmb +ydzzkumecryfjgnk +jzvmwgjutxoysaam +icrwpyhxllbardkr +jdopyntshmvltrve +afgkigxcuvmdbqou +mfzzudntmvuyhjzt +duxhgtwafcgrpihc +tsnhrkvponudumeb +sqtvnbeiigdzbjgv +eczmkqwvnsrracuo +mhehsgqwiczaiaxv +kaudmfvifovrimpd +lupikgivechdbwfr +mwaaysrndiutuiqx +aacuiiwgaannunmm +tjqjbftaqitukwzp +lrcqyskykbjpaekn +lirrvofbcqpjzxmr +jurorvzpplyelfml +qonbllojmloykjqe +sllkzqujfnbauuqp +auexjwsvphvikali +usuelbssqmbrkxyc +wyuokkfjexikptvv +wmfedauwjgbrgytl +sfwvtlzzebxzmuvw +rdhqxuechjsjcvaf +kpavhqkukugocsxu +ovnjtumxowbxduts +zgerpjufauptxgat +pevvnzjfwhjxdoxq +pmmfwxajgfziszcs +difmeqvaghuitjhs +icpwjbzcmlcterwm +ngqpvhajttxuegyh +mosjlqswdngwqsmi +frlvgpxrjolgodlu +eazwgrpcxjgoszeg +bbtsthgkjrpkiiyk +tjonoglufuvsvabe +xhkbcrofytmbzrtk +kqftfzdmpbxjynps +kmeqpocbnikdtfyv +qjjymgqxhnjwxxhp +dmgicrhgbngdtmjt +zdxrhdhbdutlawnc +afvoekuhdboxghvx +hiipezngkqcnihty +bbmqgheidenweeov +suprgwxgxwfsgjnx +adeagikyamgqphrj +zzifqinoeqaorjxg +adhgppljizpaxzld +lvxyieypvvuqjiyc +nljoakatwwwoovzn +fcrkfxclcacshhmx +ownnxqtdhqbgthch +lmfylrcdmdkgpwnj +hlwjfbvlswbzpbjr +mkofhdtljdetcyvp +synyxhifbetzarpo +agnggugngadrcxoc +uhttadmdmhidpyjw +ohfwjfhunalbubpr +pzkkkkwrlvxiuysn +kmidbxmyzkjrwjhu +egtitdydwjxmajnw +civoeoiuwtwgbqqs +dfptsguzfinqoslk +tdfvkreormspprer +zvnvbrmthatzztwi +ffkyddccrrfikjde +hrrmraevdnztiwff +qaeygykcpbtjwjbr +purwhitkmrtybslh +qzziznlswjaussel +dfcxkvdpqccdqqxj +tuotforulrrytgyn +gmtgfofgucjywkev +wkyoxudvdkbgpwhd +qbvktvfvipftztnn +otckgmojziezmojb +inxhvzbtgkjxflay +qvxapbiatuudseno +krpvqosbesnjntut +oqeukkgjsfuqkjbb +prcjnyymnqwqksiz +vuortvjxgckresko +orqlyobvkuwgathr +qnpyxlnazyfuijox +zwlblfkoklqmqzkw +hmwurwtpwnrcsanl +jzvxohuakopuzgpf +sfcpnxrviphhvxmx +qtwdeadudtqhbely +dbmkmloasqphnlgj +olylnjtkxgrubmtk +nxsdbqjuvwrrdbpq +wbabpirnpcsmpipw +hjnkyiuxpqrlvims +enzpntcjnxdpuqch +vvvqhlstzcizyimn +triozhqndbttglhv +fukvgteitwaagpzx +uhcvukfbmrvskpen +tizcyupztftzxdmt +vtkpnbpdzsaluczz +wodfoyhoekidxttm +otqocljrmwfqbxzu +linfbsnfvixlwykn +vxsluutrwskslnye +zbshygtwugixjvsi +zdcqwxvwytmzhvoo +wrseozkkcyctrmei +fblgtvogvkpqzxiy +opueqnuyngegbtnf +qxbovietpacqqxok +zacrdrrkohfygddn +gbnnvjqmkdupwzpq +qgrgmsxeotozvcak +hnppukzvzfmlokid +dzbheurndscrrtcl +wbgdkadtszebbrcw +fdmzppzphhpzyuiz +bukomunhrjrypohj +ohodhelegxootqbj +rsplgzarlrknqjyh +punjjwpsxnhpzgvu +djdfahypfjvpvibm +mlgrqsmhaozatsvy +xwktrgyuhqiquxgn +wvfaoolwtkbrisvf +plttjdmguxjwmeqr +zlvvbwvlhauyjykw +cigwkbyjhmepikej +masmylenrusgtyxs +hviqzufwyetyznze +nzqfuhrooswxxhus +pdbdetaqcrqzzwxf +oehmvziiqwkzhzib +icgpyrukiokmytoy +ooixfvwtiafnwkce +rvnmgqggpjopkihs +wywualssrmaqigqk +pdbvflnwfswsrirl +jeaezptokkccpbuj +mbdwjntysntsaaby +ldlgcawkzcwuxzpz +lwktbgrzswbsweht +ecspepmzarzmgpjm +qmfyvulkmkxjncai +izftypvwngiukrns +zgmnyjfeqffbooww +nyrkhggnprhedows +yykzzrjmlevgffah +mavaemfxhlfejfki +cmegmfjbkvpncqwf +zxidlodrezztcrij +fseasudpgvgnysjv +fupcimjupywzpqzp +iqhgokavirrcvyys +wjmkcareucnmfhui +nftflsqnkgjaexhq +mgklahzlcbapntgw +kfbmeavfxtppnrxn +nuhyvhknlufdynvn +nviogjxbluwrcoec +tyozixxxaqiuvoys +kgwlvmvgtsvxojpr +moeektyhyonfdhrb +kahvevmmfsmiiqex +xcywnqzcdqtvhiwd +fnievhiyltbvtvem +jlmndqufirwgtdxd +muypbfttoeelsnbs +rypxzbnujitfwkou +ubmmjbznskildeoj +ofnmizdeicrmkjxp +rekvectjbmdnfcib +yohrojuvdexbctdh +gwfnfdeibynzjmhz +jfznhfcqdwlpjull +scrinzycfhwkmmso +mskutzossrwoqqsi +rygoebkzgyzushhr +jpjqiycflqkexemx +arbufysjqmgaapnl +dbjerflevtgweeoj +snybnnjlmwjvhois +fszuzplntraprmbj +mkvaatolvuggikvg +zpuzuqygoxesnuyc +wnpxvmxvllxalulm +eivuuafkvudeouwy +rvzckdyixetfuehr +qgmnicdoqhveahyx +miawwngyymshjmpj +pvckyoncpqeqkbmx +llninfenrfjqxurv +kzbjnlgsqjfuzqtp +rveqcmxomvpjcwte +bzotkawzbopkosnx +ktqvpiribpypaymu +wvlzkivbukhnvram +uohntlcoguvjqqdo +ajlsiksjrcnzepkt +xsqatbldqcykwusd +ihbivgzrwpmowkop +vfayesfojmibkjpb +uaqbnijtrhvqxjtb +hhovshsfmvkvymba +jerwmyxrfeyvxcgg +hncafjwrlvdcupma +qyvigggxfylbbrzt +hiiixcyohmvnkpgk +mmitpwopgxuftdfu +iaxderqpceboixoa +zodfmjhuzhnsqfcb +sthtcbadrclrazsi +bkkkkcwegvypbrio +wmpcofuvzemunlhj +gqwebiifvqoeynro +juupusqdsvxcpsgv +rbhdfhthxelolyse +kjimpwnjfrqlqhhz +rcuigrjzarzpjgfq +htxcejfyzhydinks +sxucpdxhvqjxxjwf +omsznfcimbcwaxal +gufmtdlhgrsvcosb +bssshaqujtmluerz +uukotwjkstgwijtr +kbqkneobbrdogrxk +ljqopjcjmelgrakz +rwtfnvnzryujwkfb +dedjjbrndqnilbeh +nzinsxnpptzagwlb +lwqanydfirhnhkxy +hrjuzfumbvfccxno +okismsadkbseumnp +sfkmiaiwlktxqvwa +hauwpjjwowbunbjj +nowkofejwvutcnui +bqzzppwoslaeixro +urpfgufwbtzenkpj +xgeszvuqwxeykhef +yxoldvkyuikwqyeq +onbbhxrnmohzskgg +qcikuxakrqeugpoa +lnudcqbtyzhlpers +nxduvwfrgzaailgl +xniuwvxufzxjjrwz +ljwithcqmgvntjdj +awkftfagrfzywkhs +uedtpzxyubeveuek +bhcqdwidbjkqqhzl +iyneqjdmlhowwzxx +kvshzltcrrururty +zgfpiwajegwezupo +tkrvyanujjwmyyri +ercsefuihcmoaiep +ienjrxpmetinvbos +jnwfutjbgenlipzq +bgohjmrptfuamzbz +rtsyamajrhxbcncw +tfjdssnmztvbnscs +bgaychdlmchngqlp +kfjljiobynhwfkjo +owtdxzcpqleftbvn +ltjtimxwstvzwzjj +wbrvjjjajuombokf +zblpbpuaqbkvsxye +gwgdtbpnlhyqspdi +abipqjihjqfofmkx +nlqymnuvjpvvgova +avngotmhodpoufzn +qmdyivtzitnrjuae +xfwjmqtqdljuerxi +csuellnlcyqaaamq +slqyrcurcyuoxquo +dcjmxyzbzpohzprl +uqfnmjwniyqgsowb +rbmxpqoblyxdocqc +ebjclrdbqjhladem +ainnfhxnsgwqnmyo +eyytjjwhvodtzquf +iabjgmbbhilrcyyp +pqfnehkivuelyccc +xgjbyhfgmtseiimt +jwxyqhdbjiqqqeyy +gxsbrncqkmvaryln +vhjisxjkinaejytk +seexagcdmaedpcvh +lvudfgrcpjxzdpvd +fxtegyrqjzhmqean +dnoiseraqcoossmc +nwrhmwwbykvwmgep +udmzskejvizmtlce +hbzvqhvudfdlegaa +cghmlfqejbxewskv +bntcmjqfwomtbwsb +qezhowyopjdyhzng +todzsocdkgfxanbz +zgjkssrjlwxuhwbk +eibzljqsieriyrzr +wamxvzqyycrxotjp +epzvfkispwqynadu +dwlpfhtrafrxlyie +qhgzujhgdruowoug +girstvkahaemmxvh +baitcrqmxhazyhbl +xyanqcchbhkajdmc +gfvjmmcgfhvgnfdq +tdfdbslwncbnkzyz +jojuselkpmnnbcbb +hatdslkgxtqpmavj +dvelfeddvgjcyxkj +gnsofhkfepgwltse +mdngnobasfpewlno +qssnbcyjgmkyuoga +glvcmmjytmprqwvn +gwrixumjbcdffsdl +lozravlzvfqtsuiq +sicaflbqdxbmdlch +inwfjkyyqbwpmqlq +cuvszfotxywuzhzi +igfxyoaacoarlvay +ucjfhgdmnjvgvuni +rvvkzjsytqgiposh +jduinhjjntrmqroz +yparkxbgsfnueyll +lyeqqeisxzfsqzuj +woncskbibjnumydm +lltucklragtjmxtl +ubiyvmyhlesfxotj +uecjseeicldqrqww +xxlxkbcthufnjbnm +lhqijovvhlffpxga +fzdgqpzijitlogjz +efzzjqvwphomxdpd +jvgzvuyzobeazssc +hejfycgxywfjgbfw +yhjjmvkqfbnbliks +sffvfyywtlntsdsz +dwmxqudvxqdenrur +asnukgppdemxrzaz +nwqfnumblwvdpphx +kqsmkkspqvxzuket +cpnraovljzqiquaz +qrzgrdlyyzbyykhg +opoahcbiydyhsmqe +hjknnfdauidjeydr +hczdjjlygoezadow +rtflowzqycimllfv +sfsrgrerzlnychhq +bpahuvlblcolpjmj +albgnjkgmcrlaicl +pijyqdhfxpaxzdex +eeymiddvcwkpbpux +rqwkqoabywgggnln +vckbollyhgbgmgwh +ylzlgvnuvpynybkm +hpmbxtpfosbsjixt +ocebeihnhvkhjfqz +tvctyxoujdgwayze +efvhwxtuhapqxjen +rusksgefyidldmpo +nkmtjvddfmhirmzz +whvtsuadwofzmvrt +iiwjqvsdxudhdzzk +gucirgxaxgcassyo +rmhfasfzexeykwmr +hynlxcvsbgosjbis +huregszrcaocueen +pifezpoolrnbdqtv +unatnixzvdbqeyox +xtawlpduxgacchfe +bdvdbflqfphndduf +xtdsnjnmzccfptyt +nkhsdkhqtzqbphhg +aqcubmfkczlaxiyb +moziflxpsfubucmv +srdgnnjtfehiimqx +pwfalehdfyykrohf +sysxssmvewyfjrve +brsemdzosgqvvlxe +bimbjoshuvflkiat +hkgjasmljkpkwwku +sbnmwjvodygobpqc +bbbqycejueruihhd +corawswvlvneipyc +gcyhknmwsczcxedh +kppakbffdhntmcqp +ynulzwkfaemkcefp +pyroowjekeurlbii +iwksighrswdcnmxf +glokrdmugreygnsg +xkmvvumnfzckryop +aesviofpufygschi +csloawlirnegsssq +fkqdqqmlzuxbkzbc +uzlhzcfenxdfjdzp +poaaidrktteusvyf +zrlyfzmjzfvivcfr +qwjulskbniitgqtx +gjeszjksbfsuejki +vczdejdbfixbduaq +knjdrjthitjxluth +jweydeginrnicirl +bottrfgccqhyycsl +eiquffofoadmbuhk +lbqfutmzoksscswf +xfmdvnvfcnzjprba +uvugkjbkhlaoxmyx +wadlgtpczgvcaqqv +inzrszbtossflsxk +dbzbtashaartczrj +qbjiqpccefcfkvod +hluujmokjywotvzy +thwlliksfztcmwzh +arahybspdaqdexrq +nuojrmsgyipdvwyx +hnajdwjwmzattvst +sulcgaxezkprjbgu +rjowuugwdpkjtypw +oeugzwuhnrgiaqga +wvxnyymwftfoswij +pqxklzkjpcqscvde +tuymjzknntekglqj +odteewktugcwlhln +exsptotlfecmgehc +eeswfcijtvzgrqel +vjhrkiwmunuiwqau +zhlixepkeijoemne +pavfsmwesuvebzdd +jzovbklnngfdmyws +nbajyohtzfeoiixz +ciozmhrsjzrwxvhz +gwucrxieqbaqfjuv +uayrxrltnohexawc +flmrbhwsfbcquffm +gjyabmngkitawlxc +rwwtggvaygfbovhg +xquiegaisynictjq +oudzwuhexrwwdbyy +lengxmguyrwhrebb +uklxpglldbgqsjls +dbmvlfeyguydfsxq +zspdwdqcrmtmdtsc +mqfnzwbfqlauvrgc +amcrkzptgacywvhv +ndxmskrwrqysrndf +mwjyhsufeqhwisju +srlrukoaenyevykt +tnpjtpwawrxbikct +geczalxmgxejulcv +tvkcbqdhmuwcxqci +tiovluvwezwwgaox +zrjhtbgajkjqzmfo +vcrywduwsklepirs +lofequdigsszuioy +wxsdzomkjqymlzat +iabaczqtrfbmypuy +ibdlmudbajikcncr +rqcvkzsbwmavdwnv +ypxoyjelhllhbeog +fdnszbkezyjbttbg +uxnhrldastpdjkdz +xfrjbehtxnlyzcka +omjyfhbibqwgcpbv +eguucnoxaoprszmp +xfpypldgcmcllyzz +aypnmgqjxjqceelv +mgzharymejlafvgf +tzowgwsubbaigdok +ilsehjqpcjwmylxc +pfmouwntfhfnmrwk +csgokybgdqwnduwp +eaxwvxvvwbrovypz +nmluqvobbbmdiwwb +lnkminvfjjzqbmio +mjiiqzycqdhfietz +towlrzriicyraevq +obiloewdvbrsfwjo +lmeooaajlthsfltw +ichygipzpykkesrw +gfysloxmqdsfskvt +saqzntehjldvwtsx +pqddoemaufpfcaew +mjrxvbvwcreaybwe +ngfbrwfqnxqosoai +nesyewxreiqvhald +kqhqdlquywotcyfy +liliptyoqujensfi +nsahsaxvaepzneqq +zaickulfjajhctye +gxjzahtgbgbabtht +koxbuopaqhlsyhrp +jhzejdjidqqtjnwe +dekrkdvprfqpcqki +linwlombdqtdeyop +dvckqqbnigdcmwmx +yaxygbjpzkvnnebv +rlzkdkgaagmcpxah +cfzuyxivtknirqvt +obivkajhsjnrxxhn +lmjhayymgpseuynn +bbjyewkwadaipyju +lmzyhwomfypoftuu +gtzhqlgltvatxack +jfflcfaqqkrrltgq +txoummmnzfrlrmcg +ohemsbfuqqpucups +imsfvowcbieotlok +tcnsnccdszxfcyde +qkcdtkwuaquajazz +arcfnhmdjezdbqku +srnocgyqrlcvlhkb +mppbzvfmcdirbyfw +xiuarktilpldwgwd +ypufwmhrvzqmexpc +itpdnsfkwgrdujmj +cmpxnodtsswkyxkr +wayyxtjklfrmvbfp +mfaxphcnjczhbbwy +sjxhgwdnqcofbdra +pnxmujuylqccjvjm +ivamtjbvairwjqwl +deijtmzgpfxrclss +bzkqcaqagsynlaer +tycefobvxcvwaulz +ctbhnywezxkdsswf +urrxxebxrthtjvib +fpfelcigwqwdjucv +ngfcyyqpqulwcphb +rltkzsiipkpzlgpw +qfdsymzwhqqdkykc +balrhhxipoqzmihj +rnwalxgigswxomga +ghqnxeogckshphgr +lyyaentdizaumnla +exriodwfzosbeoib +speswfggibijfejk +yxmxgfhvmshqszrq +hcqhngvahzgawjga +qmhlsrfpesmeksur +eviafjejygakodla +kvcfeiqhynqadbzv +fusvyhowslfzqttg +girqmvwmcvntrwau +yuavizroykfkdekz +jmcwohvmzvowrhxf +kzimlcpavapynfue +wjudcdtrewfabppq +yqpteuxqgbmqfgxh +xdgiszbuhdognniu +jsguxfwhpftlcjoh +whakkvspssgjzxre +ggvnvjurlyhhijgm +krvbhjybnpemeptr +pqedgfojyjybfbzr +jzhcrsgmnkwwtpdo +yyscxoxwofslncmp +gzjhnxytmyntzths +iteigbnqbtpvqumi +zjevfzusnjukqpfw +xippcyhkfuounxqk +mcnhrcfonfdgpkyh +pinkcyuhjkexbmzj +lotxrswlxbxlxufs +fmqajrtoabpckbnu +wfkwsgmcffdgaqxg +qfrsiwnohoyfbidr +czfqbsbmiuyusaqs +ieknnjeecucghpoo +cevdgqnugupvmsge +gjkajcyjnxdrtuvr +udzhrargnujxiclq +zqqrhhmjwermjssg +ggdivtmgoqajydzz +wnpfsgtxowkjiivl +afbhqawjbotxnqpd +xjpkifkhfjeqifdn +oyfggzsstfhvticp +kercaetahymeawxy +khphblhcgmbupmzt +iggoqtqpvaebtiol +ofknifysuasshoya +qxuewroccsbogrbv +apsbnbkiopopytgu +zyahfroovfjlythh +bxhjwfgeuxlviydq +uvbhdtvaypasaswa +qamcjzrmesqgqdiz +hjnjyzrxntiycyel +wkcrwqwniczwdxgq +hibxlvkqakusswkx +mzjyuenepwdgrkty +tvywsoqslfsulses +jqwcwuuisrclircv +xanwaoebfrzhurct +ykriratovsvxxasf +qyebvtqqxbjuuwuo +telrvlwvriylnder +acksrrptgnhkeiaa +yemwfjhiqlzsvdxf +banrornfkcymmkcc +ytbhxvaeiigjpcgm +crepyazgxquposkn +xlqwdrytzwnxzwzv +xtrbfbwopxscftps +kwbytzukgseeyjla +qtfdvavvjogybxjg +ytbmvmrcxwfkgvzw +nbscbdskdeocnfzr +sqquwjbdxsxhcseg +ewqxhigqcgszfsuw +cvkyfcyfmubzwsee +dcoawetekigxgygd +ohgqnqhfimyuqhvi +otisopzzpvnhctte +bauieohjejamzien +ewnnopzkujbvhwce +aeyqlskpaehagdiv +pncudvivwnnqspxy +ytugesilgveokxcg +zoidxeelqdjesxpr +ducjccsuaygfchzj +smhgllqqqcjfubfc +nlbyyywergronmir +prdawpbjhrzsbsvj +nmgzhnjhlpcplmui +eflaogtjghdjmxxz +qolvpngucbkprrdc +ixywxcienveltgho +mwnpqtocagenkxut +iskrfbwxonkguywx +ouhtbvcaczqzmpua +srewprgddfgmdbao +dyufrltacelchlvu +czmzcbrkecixuwzz +dtbeojcztzauofuk +prrgoehpqhngfgmw +baolzvfrrevxsyke +zqadgxshwiarkzwh +vsackherluvurqqj +surbpxdulvcvgjbd +wqxytarcxzgxhvtx +vbcubqvejcfsgrac +zqnjfeapshjowzja +hekvbhtainkvbynx +knnugxoktxpvoxnh +knoaalcefpgtvlwm +qoakaunowmsuvkus +ypkvlzcduzlezqcb +ujhcagawtyepyogh +wsilcrxncnffaxjf +gbbycjuscquaycrk +aduojapeaqwivnly +ceafyxrakviagcjy +nntajnghicgnrlst +vdodpeherjmmvbje +wyyhrnegblwvdobn +xlfurpghkpbzhhif +xyppnjiljvirmqjo +kglzqahipnddanpi +omjateouxikwxowr +ocifnoopfglmndcx +emudcukfbadyijev +ooktviixetfddfmh +wtvrhloyjewdeycg +cgjncqykgutfjhvb +nkwvpswppeffmwad +hqbcmfhzkxmnrivg +mdskbvzguxvieilr +anjcvqpavhdloaqh +erksespdevjylenq +fadxwbmisazyegup +iyuiffjmcaahowhj +ygkdezmynmltodbv +fytneukxqkjattvh +woerxfadbfrvdcnz +iwsljvkyfastccoa +movylhjranlorofe +drdmicdaiwukemep +knfgtsmuhfcvvshg +ibstpbevqmdlhajn +tstwsswswrxlzrqs +estyydmzothggudf +jezogwvymvikszwa +izmqcwdyggibliet +nzpxbegurwnwrnca +kzkojelnvkwfublh +xqcssgozuxfqtiwi +tcdoigumjrgvczfv +ikcjyubjmylkwlwq +kqfivwystpqzvhan +bzukgvyoqewniivj +iduapzclhhyfladn +fbpyzxdfmkrtfaeg +yzsmlbnftftgwadz +""" + +var niceCount = 0 +input.enumerateLines { line, _ in + if line.isNice { + niceCount += 1 + } +} + +extension String { + var containsSpacedRepetition: Bool { + let last = index(before: index(before: endIndex)) + var current = startIndex + while current < last { + let next = index(after: current) + let check = index(after: next) + + if self[current] == self[check] { + print(self[current...check]) + return true + } + + current = next + } + + return false + } + + var containsDuplicatePair: Bool { + let pairs = indices.dropLast().map { self[$0...index(after: $0)] } + var pairSet: Set = [] + + for pair in pairs { + if let index = pairSet.firstIndex(of: pair), pairSet[index].endIndex <= pair.startIndex { + return true + } + + pairSet.insert(pair) + } + + return false + } + + var isNice2: Bool { + containsDuplicatePair && containsSpacedRepetition + } +} + +"aabcdefgaa".containsDuplicatePair +"xyxy".containsDuplicatePair +"aaa".containsDuplicatePair + +print(niceCount) + + +"abcdefeghi".containsSpacedRepetition + +"qjhvhtzxzqqjkmpb".isNice2 + +niceCount = 0 +input.enumerateLines { line, _ in + if line.isNice2 { + niceCount += 1 + } +} + +print(niceCount) + diff --git a/2015/Day5.playground/contents.xcplayground b/2015/Day5.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day5.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day5.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day5.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day5.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day6.playground/Contents.swift b/2015/Day6.playground/Contents.swift new file mode 100644 index 0000000..083ebde --- /dev/null +++ b/2015/Day6.playground/Contents.swift @@ -0,0 +1,422 @@ +import Foundation + +struct Range { + var minX, minY: Int + var maxX, maxY: Int +} + +enum Command { + case on(Range) + case off(Range) + case toggle(Range) +} + +struct Lights { + static let size = 1000 + var grid: [Bool] = .init(repeating: false, count: Self.size * Self.size) + + + mutating func setRange(_ range: Range, to on: Bool) { + var start = range.minY * Self.size + range.minX + let width = range.maxX - range.minX + + for _ in range.minY...range.maxY { + grid[start...start + width] = .init(repeating: on, count: width) + start += Self.size + } + } + + mutating func toggle(_ range: Range) { + var start = range.minY * Self.size + range.minX + let width = range.maxX - range.minX + + for _ in range.minY...range.maxY { + for index in start ... start+width { + grid[index].toggle() + } + start += Self.size + } + } + + var onCount: Int { + grid.reduce(0) { $0 + ($1 ? 1 : 0) } + } +} + +enum ParseError: Error { + case expectedCoordinate + case expected(String) + case expectedVerb +} + +extension Scanner { + func readCommand() throws -> Command { + let verb = try readVerb() + let range = try readRange() + + switch verb { + case .turnOn: return .on(range) + case .turnOff: return .off(range) + case .toggle: return .toggle(range) + } + } + + enum Verb: String, CaseIterable { + case turnOn = "turn on" + case turnOff = "turn off" + case toggle = "toggle" + } + + func readVerb() throws -> Verb { + for verb in Verb.allCases { + if scanString(verb.rawValue) != nil { + return verb + } + } + + throw ParseError.expectedVerb + } + + func readRange() throws -> Range { + let first = try readCoordinates() + try expect("through") + let second = try readCoordinates() + + return Range(minX: first.x, minY: first.y, maxX: second.x, maxY: second.y) + } + + func expect(_ string: String) throws { + if scanString(string) == nil { + throw ParseError.expected(string) + } + } + + func readCoordinates() throws -> (x: Int, y: Int) { + guard let x = scanInt(), + scanString(",") != nil, + let y = scanInt() + else { + throw ParseError.expectedCoordinate + } + + return (x, y) + } +} + +let input = """ +turn on 887,9 through 959,629 +turn on 454,398 through 844,448 +turn off 539,243 through 559,965 +turn off 370,819 through 676,868 +turn off 145,40 through 370,997 +turn off 301,3 through 808,453 +turn on 351,678 through 951,908 +toggle 720,196 through 897,994 +toggle 831,394 through 904,860 +toggle 753,664 through 970,926 +turn off 150,300 through 213,740 +turn on 141,242 through 932,871 +toggle 294,259 through 474,326 +toggle 678,333 through 752,957 +toggle 393,804 through 510,976 +turn off 6,964 through 411,976 +turn off 33,572 through 978,590 +turn on 579,693 through 650,978 +turn on 150,20 through 652,719 +turn off 782,143 through 808,802 +turn off 240,377 through 761,468 +turn off 899,828 through 958,967 +turn on 613,565 through 952,659 +turn on 295,36 through 964,978 +toggle 846,296 through 969,528 +turn off 211,254 through 529,491 +turn off 231,594 through 406,794 +turn off 169,791 through 758,942 +turn on 955,440 through 980,477 +toggle 944,498 through 995,928 +turn on 519,391 through 605,718 +toggle 521,303 through 617,366 +turn off 524,349 through 694,791 +toggle 391,87 through 499,792 +toggle 562,527 through 668,935 +turn off 68,358 through 857,453 +toggle 815,811 through 889,828 +turn off 666,61 through 768,87 +turn on 27,501 through 921,952 +turn on 953,102 through 983,471 +turn on 277,552 through 451,723 +turn off 64,253 through 655,960 +turn on 47,485 through 734,977 +turn off 59,119 through 699,734 +toggle 407,898 through 493,955 +toggle 912,966 through 949,991 +turn on 479,990 through 895,990 +toggle 390,589 through 869,766 +toggle 593,903 through 926,943 +toggle 358,439 through 870,528 +turn off 649,410 through 652,875 +turn on 629,834 through 712,895 +toggle 254,555 through 770,901 +toggle 641,832 through 947,850 +turn on 268,448 through 743,777 +turn off 512,123 through 625,874 +turn off 498,262 through 930,811 +turn off 835,158 through 886,242 +toggle 546,310 through 607,773 +turn on 501,505 through 896,909 +turn off 666,796 through 817,924 +toggle 987,789 through 993,809 +toggle 745,8 through 860,693 +toggle 181,983 through 731,988 +turn on 826,174 through 924,883 +turn on 239,228 through 843,993 +turn on 205,613 through 891,667 +toggle 867,873 through 984,896 +turn on 628,251 through 677,681 +toggle 276,956 through 631,964 +turn on 78,358 through 974,713 +turn on 521,360 through 773,597 +turn off 963,52 through 979,502 +turn on 117,151 through 934,622 +toggle 237,91 through 528,164 +turn on 944,269 through 975,453 +toggle 979,460 through 988,964 +turn off 440,254 through 681,507 +toggle 347,100 through 896,785 +turn off 329,592 through 369,985 +turn on 931,960 through 979,985 +toggle 703,3 through 776,36 +toggle 798,120 through 908,550 +turn off 186,605 through 914,709 +turn off 921,725 through 979,956 +toggle 167,34 through 735,249 +turn on 726,781 through 987,936 +toggle 720,336 through 847,756 +turn on 171,630 through 656,769 +turn off 417,276 through 751,500 +toggle 559,485 through 584,534 +turn on 568,629 through 690,873 +toggle 248,712 through 277,988 +toggle 345,594 through 812,723 +turn off 800,108 through 834,618 +turn off 967,439 through 986,869 +turn on 842,209 through 955,529 +turn on 132,653 through 357,696 +turn on 817,38 through 973,662 +turn off 569,816 through 721,861 +turn on 568,429 through 945,724 +turn on 77,458 through 844,685 +turn off 138,78 through 498,851 +turn on 136,21 through 252,986 +turn off 2,460 through 863,472 +turn on 172,81 through 839,332 +turn on 123,216 through 703,384 +turn off 879,644 through 944,887 +toggle 227,491 through 504,793 +toggle 580,418 through 741,479 +toggle 65,276 through 414,299 +toggle 482,486 through 838,931 +turn off 557,768 through 950,927 +turn off 615,617 through 955,864 +turn on 859,886 through 923,919 +turn on 391,330 through 499,971 +toggle 521,835 through 613,847 +turn on 822,787 through 989,847 +turn on 192,142 through 357,846 +turn off 564,945 through 985,945 +turn off 479,361 through 703,799 +toggle 56,481 through 489,978 +turn off 632,991 through 774,998 +toggle 723,526 through 945,792 +turn on 344,149 through 441,640 +toggle 568,927 through 624,952 +turn on 621,784 through 970,788 +toggle 665,783 through 795,981 +toggle 386,610 through 817,730 +toggle 440,399 through 734,417 +toggle 939,201 through 978,803 +turn off 395,883 through 554,929 +turn on 340,309 through 637,561 +turn off 875,147 through 946,481 +turn off 945,837 through 957,922 +turn off 429,982 through 691,991 +toggle 227,137 through 439,822 +toggle 4,848 through 7,932 +turn off 545,146 through 756,943 +turn on 763,863 through 937,994 +turn on 232,94 through 404,502 +turn off 742,254 through 930,512 +turn on 91,931 through 101,942 +toggle 585,106 through 651,425 +turn on 506,700 through 567,960 +turn off 548,44 through 718,352 +turn off 194,827 through 673,859 +turn off 6,645 through 509,764 +turn off 13,230 through 821,361 +turn on 734,629 through 919,631 +toggle 788,552 through 957,972 +toggle 244,747 through 849,773 +turn off 162,553 through 276,887 +turn off 569,577 through 587,604 +turn off 799,482 through 854,956 +turn on 744,535 through 909,802 +toggle 330,641 through 396,986 +turn off 927,458 through 966,564 +toggle 984,486 through 986,913 +toggle 519,682 through 632,708 +turn on 984,977 through 989,986 +toggle 766,423 through 934,495 +turn on 17,509 through 947,718 +turn on 413,783 through 631,903 +turn on 482,370 through 493,688 +turn on 433,859 through 628,938 +turn off 769,549 through 945,810 +turn on 178,853 through 539,941 +turn off 203,251 through 692,433 +turn off 525,638 through 955,794 +turn on 169,70 through 764,939 +toggle 59,352 through 896,404 +toggle 143,245 through 707,320 +turn off 103,35 through 160,949 +toggle 496,24 through 669,507 +turn off 581,847 through 847,903 +turn on 689,153 through 733,562 +turn on 821,487 through 839,699 +turn on 837,627 through 978,723 +toggle 96,748 through 973,753 +toggle 99,818 through 609,995 +turn on 731,193 through 756,509 +turn off 622,55 through 813,365 +turn on 456,490 through 576,548 +turn on 48,421 through 163,674 +turn off 853,861 through 924,964 +turn off 59,963 through 556,987 +turn on 458,710 through 688,847 +toggle 12,484 through 878,562 +turn off 241,964 through 799,983 +turn off 434,299 through 845,772 +toggle 896,725 through 956,847 +turn on 740,289 through 784,345 +turn off 395,840 through 822,845 +turn on 955,224 through 996,953 +turn off 710,186 through 957,722 +turn off 485,949 through 869,985 +turn on 848,209 through 975,376 +toggle 221,241 through 906,384 +turn on 588,49 through 927,496 +turn on 273,332 through 735,725 +turn on 505,962 through 895,962 +toggle 820,112 through 923,143 +turn on 919,792 through 978,982 +toggle 489,461 through 910,737 +turn off 202,642 through 638,940 +turn off 708,953 through 970,960 +toggle 437,291 through 546,381 +turn on 409,358 through 837,479 +turn off 756,279 through 870,943 +turn off 154,657 through 375,703 +turn off 524,622 through 995,779 +toggle 514,221 through 651,850 +toggle 808,464 through 886,646 +toggle 483,537 through 739,840 +toggle 654,769 through 831,825 +turn off 326,37 through 631,69 +turn off 590,570 through 926,656 +turn off 881,913 through 911,998 +turn on 996,102 through 998,616 +turn off 677,503 through 828,563 +turn on 860,251 through 877,441 +turn off 964,100 through 982,377 +toggle 888,403 through 961,597 +turn off 632,240 through 938,968 +toggle 731,176 through 932,413 +turn on 5,498 through 203,835 +turn on 819,352 through 929,855 +toggle 393,813 through 832,816 +toggle 725,689 through 967,888 +turn on 968,950 through 969,983 +turn off 152,628 through 582,896 +turn off 165,844 through 459,935 +turn off 882,741 through 974,786 +turn off 283,179 through 731,899 +toggle 197,366 through 682,445 +turn on 106,309 through 120,813 +toggle 950,387 through 967,782 +turn off 274,603 through 383,759 +turn off 155,665 through 284,787 +toggle 551,871 through 860,962 +turn off 30,826 through 598,892 +toggle 76,552 through 977,888 +turn on 938,180 through 994,997 +toggle 62,381 through 993,656 +toggle 625,861 through 921,941 +turn on 685,311 through 872,521 +turn on 124,934 through 530,962 +turn on 606,379 through 961,867 +turn off 792,735 through 946,783 +turn on 417,480 through 860,598 +toggle 178,91 through 481,887 +turn off 23,935 through 833,962 +toggle 317,14 through 793,425 +turn on 986,89 through 999,613 +turn off 359,201 through 560,554 +turn off 729,494 through 942,626 +turn on 204,143 through 876,610 +toggle 474,97 through 636,542 +turn off 902,924 through 976,973 +turn off 389,442 through 824,638 +turn off 622,863 through 798,863 +turn on 840,622 through 978,920 +toggle 567,374 through 925,439 +turn off 643,319 through 935,662 +toggle 185,42 through 294,810 +turn on 47,124 through 598,880 +toggle 828,303 through 979,770 +turn off 174,272 through 280,311 +turn off 540,50 through 880,212 +turn on 141,994 through 221,998 +turn on 476,695 through 483,901 +turn on 960,216 through 972,502 +toggle 752,335 through 957,733 +turn off 419,713 through 537,998 +toggle 772,846 through 994,888 +turn on 881,159 through 902,312 +turn off 537,651 through 641,816 +toggle 561,947 through 638,965 +turn on 368,458 through 437,612 +turn on 290,149 through 705,919 +turn on 711,918 through 974,945 +toggle 916,242 through 926,786 +toggle 522,272 through 773,314 +turn on 432,897 through 440,954 +turn off 132,169 through 775,380 +toggle 52,205 through 693,747 +toggle 926,309 through 976,669 +turn off 838,342 through 938,444 +turn on 144,431 through 260,951 +toggle 780,318 through 975,495 +turn off 185,412 through 796,541 +turn on 879,548 through 892,860 +turn on 294,132 through 460,338 +turn on 823,500 through 899,529 +turn off 225,603 through 483,920 +toggle 717,493 through 930,875 +toggle 534,948 through 599,968 +turn on 522,730 through 968,950 +turn off 102,229 through 674,529 +""" + +let scanner = Scanner(string: input) + +var grid = Lights() +while !scanner.isAtEnd { + let command = try scanner.readCommand() + switch command { + case let .on(range): grid.setRange(range, to: true) + case let .off(range): grid.setRange(range, to: false) + case let .toggle(range): grid.toggle(range) + } +} + +grid.onCount + diff --git a/2015/Day6.playground/contents.xcplayground b/2015/Day6.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day6.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day6.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day6.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day6.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day6/Day6.xcodeproj/project.pbxproj b/2015/Day6/Day6.xcodeproj/project.pbxproj new file mode 100644 index 0000000..99f707b --- /dev/null +++ b/2015/Day6/Day6.xcodeproj/project.pbxproj @@ -0,0 +1,291 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 55; + objects = { + +/* Begin PBXBuildFile section */ + 2628B52326EDF9EE00ECED43 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2628B52226EDF9EE00ECED43 /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 2628B51D26EDF9EE00ECED43 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 2628B51F26EDF9EE00ECED43 /* Day6 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Day6; sourceTree = BUILT_PRODUCTS_DIR; }; + 2628B52226EDF9EE00ECED43 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 2628B51C26EDF9EE00ECED43 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 2628B51626EDF9EE00ECED43 = { + isa = PBXGroup; + children = ( + 2628B52126EDF9EE00ECED43 /* Day6 */, + 2628B52026EDF9EE00ECED43 /* Products */, + ); + sourceTree = ""; + }; + 2628B52026EDF9EE00ECED43 /* Products */ = { + isa = PBXGroup; + children = ( + 2628B51F26EDF9EE00ECED43 /* Day6 */, + ); + name = Products; + sourceTree = ""; + }; + 2628B52126EDF9EE00ECED43 /* Day6 */ = { + isa = PBXGroup; + children = ( + 2628B52226EDF9EE00ECED43 /* main.swift */, + ); + path = Day6; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 2628B51E26EDF9EE00ECED43 /* Day6 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2628B52626EDF9EE00ECED43 /* Build configuration list for PBXNativeTarget "Day6" */; + buildPhases = ( + 2628B51B26EDF9EE00ECED43 /* Sources */, + 2628B51C26EDF9EE00ECED43 /* Frameworks */, + 2628B51D26EDF9EE00ECED43 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Day6; + productName = Day6; + productReference = 2628B51F26EDF9EE00ECED43 /* Day6 */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 2628B51726EDF9EE00ECED43 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1300; + LastUpgradeCheck = 1300; + TargetAttributes = { + 2628B51E26EDF9EE00ECED43 = { + CreatedOnToolsVersion = 13.0; + }; + }; + }; + buildConfigurationList = 2628B51A26EDF9EE00ECED43 /* Build configuration list for PBXProject "Day6" */; + compatibilityVersion = "Xcode 13.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 2628B51626EDF9EE00ECED43; + productRefGroup = 2628B52026EDF9EE00ECED43 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 2628B51E26EDF9EE00ECED43 /* Day6 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 2628B51B26EDF9EE00ECED43 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2628B52326EDF9EE00ECED43 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 2628B52426EDF9EE00ECED43 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + 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 = gnu11; + 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 = 11.5; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 2628B52526EDF9EE00ECED43 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + 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 = gnu11; + 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 = 11.5; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 2628B52726EDF9EE00ECED43 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 722B335UM5; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 2628B52826EDF9EE00ECED43 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 722B335UM5; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 2628B51A26EDF9EE00ECED43 /* Build configuration list for PBXProject "Day6" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2628B52426EDF9EE00ECED43 /* Debug */, + 2628B52526EDF9EE00ECED43 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2628B52626EDF9EE00ECED43 /* Build configuration list for PBXNativeTarget "Day6" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2628B52726EDF9EE00ECED43 /* Debug */, + 2628B52826EDF9EE00ECED43 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 2628B51726EDF9EE00ECED43 /* Project object */; +} diff --git a/2015/Day6/Day6.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/2015/Day6/Day6.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/2015/Day6/Day6.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day6/Day6.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/2015/Day6/Day6.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/2015/Day6/Day6.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/2015/Day6/Day6/main.swift b/2015/Day6/Day6/main.swift new file mode 100644 index 0000000..c3c4bb5 --- /dev/null +++ b/2015/Day6/Day6/main.swift @@ -0,0 +1,433 @@ +import Foundation +import CoreGraphics +import ImageIO + +struct Range { + var minX, minY: Int + var maxX, maxY: Int +} + +enum Command { + case on(Range) + case off(Range) + case toggle(Range) +} + +struct Lights { + static let size = 1000 + var grid: [Int8] = .init(repeating: 0, count: Self.size * Self.size) + + + mutating func changeRange(_ range: Range, by: Int8) { + var start = range.minY * Self.size + range.minX + let width = range.maxX - range.minX + + for _ in range.minY...range.maxY { + for index in start ... start+width { + grid[index] = max(0, grid[index] + by) + } + start += Self.size + } + } + + var brightness: Int { + grid.reduce(0) { $0 + Int($1) } + } +} + +enum ParseError: Error { + case expectedCoordinate + case expected(String) + case expectedVerb +} + +extension Scanner { + func readCommand() throws -> Command { + let verb = try readVerb() + let range = try readRange() + + switch verb { + case .turnOn: return .on(range) + case .turnOff: return .off(range) + case .toggle: return .toggle(range) + } + } + + enum Verb: String, CaseIterable { + case turnOn = "turn on" + case turnOff = "turn off" + case toggle = "toggle" + } + + func readVerb() throws -> Verb { + for verb in Verb.allCases { + if scanString(verb.rawValue) != nil { + return verb + } + } + + throw ParseError.expectedVerb + } + + func readRange() throws -> Range { + let first = try readCoordinates() + try expect("through") + let second = try readCoordinates() + + return Range(minX: first.x, minY: first.y, maxX: second.x, maxY: second.y) + } + + func expect(_ string: String) throws { + if scanString(string) == nil { + throw ParseError.expected(string) + } + } + + func readCoordinates() throws -> (x: Int, y: Int) { + guard let x = scanInt(), + scanString(",") != nil, + let y = scanInt() + else { + throw ParseError.expectedCoordinate + } + + return (x, y) + } +} + +let input = """ +turn on 887,9 through 959,629 +turn on 454,398 through 844,448 +turn off 539,243 through 559,965 +turn off 370,819 through 676,868 +turn off 145,40 through 370,997 +turn off 301,3 through 808,453 +turn on 351,678 through 951,908 +toggle 720,196 through 897,994 +toggle 831,394 through 904,860 +toggle 753,664 through 970,926 +turn off 150,300 through 213,740 +turn on 141,242 through 932,871 +toggle 294,259 through 474,326 +toggle 678,333 through 752,957 +toggle 393,804 through 510,976 +turn off 6,964 through 411,976 +turn off 33,572 through 978,590 +turn on 579,693 through 650,978 +turn on 150,20 through 652,719 +turn off 782,143 through 808,802 +turn off 240,377 through 761,468 +turn off 899,828 through 958,967 +turn on 613,565 through 952,659 +turn on 295,36 through 964,978 +toggle 846,296 through 969,528 +turn off 211,254 through 529,491 +turn off 231,594 through 406,794 +turn off 169,791 through 758,942 +turn on 955,440 through 980,477 +toggle 944,498 through 995,928 +turn on 519,391 through 605,718 +toggle 521,303 through 617,366 +turn off 524,349 through 694,791 +toggle 391,87 through 499,792 +toggle 562,527 through 668,935 +turn off 68,358 through 857,453 +toggle 815,811 through 889,828 +turn off 666,61 through 768,87 +turn on 27,501 through 921,952 +turn on 953,102 through 983,471 +turn on 277,552 through 451,723 +turn off 64,253 through 655,960 +turn on 47,485 through 734,977 +turn off 59,119 through 699,734 +toggle 407,898 through 493,955 +toggle 912,966 through 949,991 +turn on 479,990 through 895,990 +toggle 390,589 through 869,766 +toggle 593,903 through 926,943 +toggle 358,439 through 870,528 +turn off 649,410 through 652,875 +turn on 629,834 through 712,895 +toggle 254,555 through 770,901 +toggle 641,832 through 947,850 +turn on 268,448 through 743,777 +turn off 512,123 through 625,874 +turn off 498,262 through 930,811 +turn off 835,158 through 886,242 +toggle 546,310 through 607,773 +turn on 501,505 through 896,909 +turn off 666,796 through 817,924 +toggle 987,789 through 993,809 +toggle 745,8 through 860,693 +toggle 181,983 through 731,988 +turn on 826,174 through 924,883 +turn on 239,228 through 843,993 +turn on 205,613 through 891,667 +toggle 867,873 through 984,896 +turn on 628,251 through 677,681 +toggle 276,956 through 631,964 +turn on 78,358 through 974,713 +turn on 521,360 through 773,597 +turn off 963,52 through 979,502 +turn on 117,151 through 934,622 +toggle 237,91 through 528,164 +turn on 944,269 through 975,453 +toggle 979,460 through 988,964 +turn off 440,254 through 681,507 +toggle 347,100 through 896,785 +turn off 329,592 through 369,985 +turn on 931,960 through 979,985 +toggle 703,3 through 776,36 +toggle 798,120 through 908,550 +turn off 186,605 through 914,709 +turn off 921,725 through 979,956 +toggle 167,34 through 735,249 +turn on 726,781 through 987,936 +toggle 720,336 through 847,756 +turn on 171,630 through 656,769 +turn off 417,276 through 751,500 +toggle 559,485 through 584,534 +turn on 568,629 through 690,873 +toggle 248,712 through 277,988 +toggle 345,594 through 812,723 +turn off 800,108 through 834,618 +turn off 967,439 through 986,869 +turn on 842,209 through 955,529 +turn on 132,653 through 357,696 +turn on 817,38 through 973,662 +turn off 569,816 through 721,861 +turn on 568,429 through 945,724 +turn on 77,458 through 844,685 +turn off 138,78 through 498,851 +turn on 136,21 through 252,986 +turn off 2,460 through 863,472 +turn on 172,81 through 839,332 +turn on 123,216 through 703,384 +turn off 879,644 through 944,887 +toggle 227,491 through 504,793 +toggle 580,418 through 741,479 +toggle 65,276 through 414,299 +toggle 482,486 through 838,931 +turn off 557,768 through 950,927 +turn off 615,617 through 955,864 +turn on 859,886 through 923,919 +turn on 391,330 through 499,971 +toggle 521,835 through 613,847 +turn on 822,787 through 989,847 +turn on 192,142 through 357,846 +turn off 564,945 through 985,945 +turn off 479,361 through 703,799 +toggle 56,481 through 489,978 +turn off 632,991 through 774,998 +toggle 723,526 through 945,792 +turn on 344,149 through 441,640 +toggle 568,927 through 624,952 +turn on 621,784 through 970,788 +toggle 665,783 through 795,981 +toggle 386,610 through 817,730 +toggle 440,399 through 734,417 +toggle 939,201 through 978,803 +turn off 395,883 through 554,929 +turn on 340,309 through 637,561 +turn off 875,147 through 946,481 +turn off 945,837 through 957,922 +turn off 429,982 through 691,991 +toggle 227,137 through 439,822 +toggle 4,848 through 7,932 +turn off 545,146 through 756,943 +turn on 763,863 through 937,994 +turn on 232,94 through 404,502 +turn off 742,254 through 930,512 +turn on 91,931 through 101,942 +toggle 585,106 through 651,425 +turn on 506,700 through 567,960 +turn off 548,44 through 718,352 +turn off 194,827 through 673,859 +turn off 6,645 through 509,764 +turn off 13,230 through 821,361 +turn on 734,629 through 919,631 +toggle 788,552 through 957,972 +toggle 244,747 through 849,773 +turn off 162,553 through 276,887 +turn off 569,577 through 587,604 +turn off 799,482 through 854,956 +turn on 744,535 through 909,802 +toggle 330,641 through 396,986 +turn off 927,458 through 966,564 +toggle 984,486 through 986,913 +toggle 519,682 through 632,708 +turn on 984,977 through 989,986 +toggle 766,423 through 934,495 +turn on 17,509 through 947,718 +turn on 413,783 through 631,903 +turn on 482,370 through 493,688 +turn on 433,859 through 628,938 +turn off 769,549 through 945,810 +turn on 178,853 through 539,941 +turn off 203,251 through 692,433 +turn off 525,638 through 955,794 +turn on 169,70 through 764,939 +toggle 59,352 through 896,404 +toggle 143,245 through 707,320 +turn off 103,35 through 160,949 +toggle 496,24 through 669,507 +turn off 581,847 through 847,903 +turn on 689,153 through 733,562 +turn on 821,487 through 839,699 +turn on 837,627 through 978,723 +toggle 96,748 through 973,753 +toggle 99,818 through 609,995 +turn on 731,193 through 756,509 +turn off 622,55 through 813,365 +turn on 456,490 through 576,548 +turn on 48,421 through 163,674 +turn off 853,861 through 924,964 +turn off 59,963 through 556,987 +turn on 458,710 through 688,847 +toggle 12,484 through 878,562 +turn off 241,964 through 799,983 +turn off 434,299 through 845,772 +toggle 896,725 through 956,847 +turn on 740,289 through 784,345 +turn off 395,840 through 822,845 +turn on 955,224 through 996,953 +turn off 710,186 through 957,722 +turn off 485,949 through 869,985 +turn on 848,209 through 975,376 +toggle 221,241 through 906,384 +turn on 588,49 through 927,496 +turn on 273,332 through 735,725 +turn on 505,962 through 895,962 +toggle 820,112 through 923,143 +turn on 919,792 through 978,982 +toggle 489,461 through 910,737 +turn off 202,642 through 638,940 +turn off 708,953 through 970,960 +toggle 437,291 through 546,381 +turn on 409,358 through 837,479 +turn off 756,279 through 870,943 +turn off 154,657 through 375,703 +turn off 524,622 through 995,779 +toggle 514,221 through 651,850 +toggle 808,464 through 886,646 +toggle 483,537 through 739,840 +toggle 654,769 through 831,825 +turn off 326,37 through 631,69 +turn off 590,570 through 926,656 +turn off 881,913 through 911,998 +turn on 996,102 through 998,616 +turn off 677,503 through 828,563 +turn on 860,251 through 877,441 +turn off 964,100 through 982,377 +toggle 888,403 through 961,597 +turn off 632,240 through 938,968 +toggle 731,176 through 932,413 +turn on 5,498 through 203,835 +turn on 819,352 through 929,855 +toggle 393,813 through 832,816 +toggle 725,689 through 967,888 +turn on 968,950 through 969,983 +turn off 152,628 through 582,896 +turn off 165,844 through 459,935 +turn off 882,741 through 974,786 +turn off 283,179 through 731,899 +toggle 197,366 through 682,445 +turn on 106,309 through 120,813 +toggle 950,387 through 967,782 +turn off 274,603 through 383,759 +turn off 155,665 through 284,787 +toggle 551,871 through 860,962 +turn off 30,826 through 598,892 +toggle 76,552 through 977,888 +turn on 938,180 through 994,997 +toggle 62,381 through 993,656 +toggle 625,861 through 921,941 +turn on 685,311 through 872,521 +turn on 124,934 through 530,962 +turn on 606,379 through 961,867 +turn off 792,735 through 946,783 +turn on 417,480 through 860,598 +toggle 178,91 through 481,887 +turn off 23,935 through 833,962 +toggle 317,14 through 793,425 +turn on 986,89 through 999,613 +turn off 359,201 through 560,554 +turn off 729,494 through 942,626 +turn on 204,143 through 876,610 +toggle 474,97 through 636,542 +turn off 902,924 through 976,973 +turn off 389,442 through 824,638 +turn off 622,863 through 798,863 +turn on 840,622 through 978,920 +toggle 567,374 through 925,439 +turn off 643,319 through 935,662 +toggle 185,42 through 294,810 +turn on 47,124 through 598,880 +toggle 828,303 through 979,770 +turn off 174,272 through 280,311 +turn off 540,50 through 880,212 +turn on 141,994 through 221,998 +turn on 476,695 through 483,901 +turn on 960,216 through 972,502 +toggle 752,335 through 957,733 +turn off 419,713 through 537,998 +toggle 772,846 through 994,888 +turn on 881,159 through 902,312 +turn off 537,651 through 641,816 +toggle 561,947 through 638,965 +turn on 368,458 through 437,612 +turn on 290,149 through 705,919 +turn on 711,918 through 974,945 +toggle 916,242 through 926,786 +toggle 522,272 through 773,314 +turn on 432,897 through 440,954 +turn off 132,169 through 775,380 +toggle 52,205 through 693,747 +toggle 926,309 through 976,669 +turn off 838,342 through 938,444 +turn on 144,431 through 260,951 +toggle 780,318 through 975,495 +turn off 185,412 through 796,541 +turn on 879,548 through 892,860 +turn on 294,132 through 460,338 +turn on 823,500 through 899,529 +turn off 225,603 through 483,920 +toggle 717,493 through 930,875 +toggle 534,948 through 599,968 +turn on 522,730 through 968,950 +turn off 102,229 through 674,529 +""" + +let scanner = Scanner(string: input) + +extension Range { + var size: Int { + (maxX - minX + 1) * (maxY - minY + 1) + } +} + +var totalBrightness = 0 + +var grid = Lights() +while !scanner.isAtEnd { + let command = try scanner.readCommand() + switch command { + case let .on(range): + grid.changeRange(range, by: 1) + + case let .off(range): + grid.changeRange(range, by: -1) + + case let .toggle(range): + grid.changeRange(range, by: 2) + } +} + +print(grid.brightness) + +let image = CGImage(width: Lights.size, height: Lights.size, bitsPerComponent: 8, bitsPerPixel: 8, bytesPerRow: Lights.size, space: .init(name: CGColorSpace.linearGray)!, bitmapInfo: .init(rawValue: 0), provider: .init(dataInfo: nil, data: &grid.grid, size: grid.grid.count, releaseData: { _, _, _ in })!, decode: nil, shouldInterpolate: false, intent: .defaultIntent) + +let dest = CGImageDestinationCreateWithURL(URL(fileURLWithPath: "test.png") as CFURL, kUTTypePNG, 1, nil)! +CGImageDestinationAddImage(dest, image!, nil) +CGImageDestinationFinalize(dest) + diff --git a/2015/Day7/Day7.xcodeproj/project.pbxproj b/2015/Day7/Day7.xcodeproj/project.pbxproj new file mode 100644 index 0000000..6cf3cd7 --- /dev/null +++ b/2015/Day7/Day7.xcodeproj/project.pbxproj @@ -0,0 +1,291 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 55; + objects = { + +/* Begin PBXBuildFile section */ + 2628B53626EE043900ECED43 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2628B53526EE043900ECED43 /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 2628B53026EE043900ECED43 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 2628B53226EE043900ECED43 /* Day7 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Day7; sourceTree = BUILT_PRODUCTS_DIR; }; + 2628B53526EE043900ECED43 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 2628B52F26EE043900ECED43 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 2628B52926EE043900ECED43 = { + isa = PBXGroup; + children = ( + 2628B53426EE043900ECED43 /* Day7 */, + 2628B53326EE043900ECED43 /* Products */, + ); + sourceTree = ""; + }; + 2628B53326EE043900ECED43 /* Products */ = { + isa = PBXGroup; + children = ( + 2628B53226EE043900ECED43 /* Day7 */, + ); + name = Products; + sourceTree = ""; + }; + 2628B53426EE043900ECED43 /* Day7 */ = { + isa = PBXGroup; + children = ( + 2628B53526EE043900ECED43 /* main.swift */, + ); + path = Day7; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 2628B53126EE043900ECED43 /* Day7 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2628B53926EE043900ECED43 /* Build configuration list for PBXNativeTarget "Day7" */; + buildPhases = ( + 2628B52E26EE043900ECED43 /* Sources */, + 2628B52F26EE043900ECED43 /* Frameworks */, + 2628B53026EE043900ECED43 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Day7; + productName = Day7; + productReference = 2628B53226EE043900ECED43 /* Day7 */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 2628B52A26EE043900ECED43 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1300; + LastUpgradeCheck = 1300; + TargetAttributes = { + 2628B53126EE043900ECED43 = { + CreatedOnToolsVersion = 13.0; + }; + }; + }; + buildConfigurationList = 2628B52D26EE043900ECED43 /* Build configuration list for PBXProject "Day7" */; + compatibilityVersion = "Xcode 13.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 2628B52926EE043900ECED43; + productRefGroup = 2628B53326EE043900ECED43 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 2628B53126EE043900ECED43 /* Day7 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 2628B52E26EE043900ECED43 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2628B53626EE043900ECED43 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 2628B53726EE043900ECED43 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + 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 = gnu11; + 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 = 11.5; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 2628B53826EE043900ECED43 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + 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 = gnu11; + 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 = 11.5; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 2628B53A26EE043900ECED43 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 722B335UM5; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 2628B53B26EE043900ECED43 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 722B335UM5; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 2628B52D26EE043900ECED43 /* Build configuration list for PBXProject "Day7" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2628B53726EE043900ECED43 /* Debug */, + 2628B53826EE043900ECED43 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2628B53926EE043900ECED43 /* Build configuration list for PBXNativeTarget "Day7" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2628B53A26EE043900ECED43 /* Debug */, + 2628B53B26EE043900ECED43 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 2628B52A26EE043900ECED43 /* Project object */; +} diff --git a/2015/Day7/Day7.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/2015/Day7/Day7.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/2015/Day7/Day7.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day7/Day7.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/2015/Day7/Day7.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/2015/Day7/Day7.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/2015/Day7/Day7/main.swift b/2015/Day7/Day7/main.swift new file mode 100644 index 0000000..8a70871 --- /dev/null +++ b/2015/Day7/Day7/main.swift @@ -0,0 +1,531 @@ +import Foundation + +enum EvaluationError: Error { + case signalMissing(String) + case circularDefinition(String) +} + +protocol Context { + func evaluate(_ signal: String) throws -> UInt16 +} + +enum Ref { + case value(UInt16) + case signal(String) + + func evaluate(context: Context) throws -> UInt16 { + switch self { + case .value(let value): return value + case .signal(let name): return try context.evaluate(name) + } + } +} + +enum Signal { + case value(Ref) + case and(Ref, Ref) + case leftShift(Ref, amount: Int) + case rightShift(Ref, amount: Int) + case not(Ref) + case or(Ref, Ref) + + func evaluate(context: Context) throws -> UInt16 { + switch self { + case .value(let value): return try value.evaluate(context: context) + case .and(let a, let b): return try a.evaluate(context: context) & b.evaluate(context: context) + case .or(let a, let b): return try a.evaluate(context: context) | b.evaluate(context: context) + case .not(let other): return try ~other.evaluate(context: context) + case .leftShift(let other, amount: let amount): return try other.evaluate(context: context) << amount + case .rightShift(let other, amount: let amount): return try other.evaluate(context: context) >> amount + } + } +} + + +enum ParseError: Error { + case expected(String) + case nameExpected + case intExpected + case operatorExpected +} + +extension Scanner { + func expect(_ string: String) throws { + guard scanString(string) != nil else { + throw ParseError.expected(string) + } + } + + func circuit() throws -> [String: Signal] { + var result: [String: Signal] = [:] + while !isAtEnd { + let (signal, name) = try connection() + result[name] = signal + } + + return result + } + + func connection() throws -> (Signal, String) { + let signal = try signal() + try expect("->") + let name = try name() + + return (signal, name) + } + + func signal() throws -> Signal { + if scanString("NOT") != nil { + let signal = try ref() + return .not(signal) + } + + let firstOperand = try ref() + + if let op = binaryOperator() { + let secondOperand = try ref() + switch op { + case .and: return .and(firstOperand, secondOperand) + case .or: return .or(firstOperand, secondOperand) + } + } + + if let (shift, amount) = try shiftOperator() { + switch shift { + case .left: return .leftShift(firstOperand, amount: amount) + case .right: return .rightShift(firstOperand, amount: amount) + } + } + + return .value(firstOperand) + + } + + enum BinaryOperator: String, CaseIterable { + case and = "AND" + case or = "OR" + } + + func oneOf() -> T? where T: RawRepresentable, T: CaseIterable, T.RawValue == String { + for item in T.allCases { + if scanString(item.rawValue) != nil { + return item + } + } + + return nil + } + + func binaryOperator() -> BinaryOperator? { + oneOf() + } + + + enum Shift: String, CaseIterable { + case left = "LSHIFT" + case right = "RSHIFT" + } + + func shiftOperator() throws -> (Shift, Int)? { + guard let direction: Shift = oneOf() else { return nil } + guard let amount = scanInt() else { + throw ParseError.intExpected + } + return (direction, amount) + } + + func ref() throws -> Ref { + if let int = scanInt() { + return .value(UInt16(int)) + } + + return try .signal(name()) + } + + func name() throws -> String { + guard let name = scanCharacters(from: .letters) else { + throw ParseError.nameExpected + } + + return name + } +} + +let input = """ +af AND ah -> ai +NOT lk -> ll +hz RSHIFT 1 -> is +NOT go -> gp +du OR dt -> dv +x RSHIFT 5 -> aa +at OR az -> ba +eo LSHIFT 15 -> es +ci OR ct -> cu +b RSHIFT 5 -> f +fm OR fn -> fo +NOT ag -> ah +v OR w -> x +g AND i -> j +an LSHIFT 15 -> ar +1 AND cx -> cy +jq AND jw -> jy +iu RSHIFT 5 -> ix +gl AND gm -> go +NOT bw -> bx +jp RSHIFT 3 -> jr +hg AND hh -> hj +bv AND bx -> by +er OR es -> et +kl OR kr -> ks +et RSHIFT 1 -> fm +e AND f -> h +u LSHIFT 1 -> ao +he RSHIFT 1 -> hx +eg AND ei -> ej +bo AND bu -> bw +dz OR ef -> eg +dy RSHIFT 3 -> ea +gl OR gm -> gn +da LSHIFT 1 -> du +au OR av -> aw +gj OR gu -> gv +eu OR fa -> fb +lg OR lm -> ln +e OR f -> g +NOT dm -> dn +NOT l -> m +aq OR ar -> as +gj RSHIFT 5 -> gm +hm AND ho -> hp +ge LSHIFT 15 -> gi +jp RSHIFT 1 -> ki +hg OR hh -> hi +lc LSHIFT 1 -> lw +km OR kn -> ko +eq LSHIFT 1 -> fk +1 AND am -> an +gj RSHIFT 1 -> hc +aj AND al -> am +gj AND gu -> gw +ko AND kq -> kr +ha OR gz -> hb +bn OR by -> bz +iv OR jb -> jc +NOT ac -> ad +bo OR bu -> bv +d AND j -> l +bk LSHIFT 1 -> ce +de OR dk -> dl +dd RSHIFT 1 -> dw +hz AND ik -> im +NOT jd -> je +fo RSHIFT 2 -> fp +hb LSHIFT 1 -> hv +lf RSHIFT 2 -> lg +gj RSHIFT 3 -> gl +ki OR kj -> kk +NOT ak -> al +ld OR le -> lf +ci RSHIFT 3 -> ck +1 AND cc -> cd +NOT kx -> ky +fp OR fv -> fw +ev AND ew -> ey +dt LSHIFT 15 -> dx +NOT ax -> ay +bp AND bq -> bs +NOT ii -> ij +ci AND ct -> cv +iq OR ip -> ir +x RSHIFT 2 -> y +fq OR fr -> fs +bn RSHIFT 5 -> bq +0 -> c +14146 -> b +d OR j -> k +z OR aa -> ab +gf OR ge -> gg +df OR dg -> dh +NOT hj -> hk +NOT di -> dj +fj LSHIFT 15 -> fn +lf RSHIFT 1 -> ly +b AND n -> p +jq OR jw -> jx +gn AND gp -> gq +x RSHIFT 1 -> aq +ex AND ez -> fa +NOT fc -> fd +bj OR bi -> bk +as RSHIFT 5 -> av +hu LSHIFT 15 -> hy +NOT gs -> gt +fs AND fu -> fv +dh AND dj -> dk +bz AND cb -> cc +dy RSHIFT 1 -> er +hc OR hd -> he +fo OR fz -> ga +t OR s -> u +b RSHIFT 2 -> d +NOT jy -> jz +hz RSHIFT 2 -> ia +kk AND kv -> kx +ga AND gc -> gd +fl LSHIFT 1 -> gf +bn AND by -> ca +NOT hr -> hs +NOT bs -> bt +lf RSHIFT 3 -> lh +au AND av -> ax +1 AND gd -> ge +jr OR js -> jt +fw AND fy -> fz +NOT iz -> ja +c LSHIFT 1 -> t +dy RSHIFT 5 -> eb +bp OR bq -> br +NOT h -> i +1 AND ds -> dt +ab AND ad -> ae +ap LSHIFT 1 -> bj +br AND bt -> bu +NOT ca -> cb +NOT el -> em +s LSHIFT 15 -> w +gk OR gq -> gr +ff AND fh -> fi +kf LSHIFT 15 -> kj +fp AND fv -> fx +lh OR li -> lj +bn RSHIFT 3 -> bp +jp OR ka -> kb +lw OR lv -> lx +iy AND ja -> jb +dy OR ej -> ek +1 AND bh -> bi +NOT kt -> ku +ao OR an -> ap +ia AND ig -> ii +NOT ey -> ez +bn RSHIFT 1 -> cg +fk OR fj -> fl +ce OR cd -> cf +eu AND fa -> fc +kg OR kf -> kh +jr AND js -> ju +iu RSHIFT 3 -> iw +df AND dg -> di +dl AND dn -> do +la LSHIFT 15 -> le +fo RSHIFT 1 -> gh +NOT gw -> gx +NOT gb -> gc +ir LSHIFT 1 -> jl +x AND ai -> ak +he RSHIFT 5 -> hh +1 AND lu -> lv +NOT ft -> fu +gh OR gi -> gj +lf RSHIFT 5 -> li +x RSHIFT 3 -> z +b RSHIFT 3 -> e +he RSHIFT 2 -> hf +NOT fx -> fy +jt AND jv -> jw +hx OR hy -> hz +jp AND ka -> kc +fb AND fd -> fe +hz OR ik -> il +ci RSHIFT 1 -> db +fo AND fz -> gb +fq AND fr -> ft +gj RSHIFT 2 -> gk +cg OR ch -> ci +cd LSHIFT 15 -> ch +jm LSHIFT 1 -> kg +ih AND ij -> ik +fo RSHIFT 3 -> fq +fo RSHIFT 5 -> fr +1 AND fi -> fj +1 AND kz -> la +iu AND jf -> jh +cq AND cs -> ct +dv LSHIFT 1 -> ep +hf OR hl -> hm +km AND kn -> kp +de AND dk -> dm +dd RSHIFT 5 -> dg +NOT lo -> lp +NOT ju -> jv +NOT fg -> fh +cm AND co -> cp +ea AND eb -> ed +dd RSHIFT 3 -> df +gr AND gt -> gu +ep OR eo -> eq +cj AND cp -> cr +lf OR lq -> lr +gg LSHIFT 1 -> ha +et RSHIFT 2 -> eu +NOT jh -> ji +ek AND em -> en +jk LSHIFT 15 -> jo +ia OR ig -> ih +gv AND gx -> gy +et AND fe -> fg +lh AND li -> lk +1 AND io -> ip +kb AND kd -> ke +kk RSHIFT 5 -> kn +id AND if -> ig +NOT ls -> lt +dw OR dx -> dy +dd AND do -> dq +lf AND lq -> ls +NOT kc -> kd +dy AND ej -> el +1 AND ke -> kf +et OR fe -> ff +hz RSHIFT 5 -> ic +dd OR do -> dp +cj OR cp -> cq +NOT dq -> dr +kk RSHIFT 1 -> ld +jg AND ji -> jj +he OR hp -> hq +hi AND hk -> hl +dp AND dr -> ds +dz AND ef -> eh +hz RSHIFT 3 -> ib +db OR dc -> dd +hw LSHIFT 1 -> iq +he AND hp -> hr +NOT cr -> cs +lg AND lm -> lo +hv OR hu -> hw +il AND in -> io +NOT eh -> ei +gz LSHIFT 15 -> hd +gk AND gq -> gs +1 AND en -> eo +NOT kp -> kq +et RSHIFT 5 -> ew +lj AND ll -> lm +he RSHIFT 3 -> hg +et RSHIFT 3 -> ev +as AND bd -> bf +cu AND cw -> cx +jx AND jz -> ka +b OR n -> o +be AND bg -> bh +1 AND ht -> hu +1 AND gy -> gz +NOT hn -> ho +ck OR cl -> cm +ec AND ee -> ef +lv LSHIFT 15 -> lz +ks AND ku -> kv +NOT ie -> if +hf AND hl -> hn +1 AND r -> s +ib AND ic -> ie +hq AND hs -> ht +y AND ae -> ag +NOT ed -> ee +bi LSHIFT 15 -> bm +dy RSHIFT 2 -> dz +ci RSHIFT 2 -> cj +NOT bf -> bg +NOT im -> in +ev OR ew -> ex +ib OR ic -> id +bn RSHIFT 2 -> bo +dd RSHIFT 2 -> de +bl OR bm -> bn +as RSHIFT 1 -> bl +ea OR eb -> ec +ln AND lp -> lq +kk RSHIFT 3 -> km +is OR it -> iu +iu RSHIFT 2 -> iv +as OR bd -> be +ip LSHIFT 15 -> it +iw OR ix -> iy +kk RSHIFT 2 -> kl +NOT bb -> bc +ci RSHIFT 5 -> cl +ly OR lz -> ma +z AND aa -> ac +iu RSHIFT 1 -> jn +cy LSHIFT 15 -> dc +cf LSHIFT 1 -> cz +as RSHIFT 3 -> au +cz OR cy -> da +kw AND ky -> kz +lx -> a +iw AND ix -> iz +lr AND lt -> lu +jp RSHIFT 5 -> js +aw AND ay -> az +jc AND je -> jf +lb OR la -> lc +NOT cn -> co +kh LSHIFT 1 -> lb +1 AND jj -> jk +y OR ae -> af +ck AND cl -> cn +kk OR kv -> kw +NOT cv -> cw +kl AND kr -> kt +iu OR jf -> jg +at AND az -> bb +jp RSHIFT 2 -> jq +iv AND jb -> jd +jn OR jo -> jp +x OR ai -> aj +ba AND bc -> bd +jl OR jk -> jm +b RSHIFT 1 -> v +o AND q -> r +NOT p -> q +k AND m -> n +as RSHIFT 2 -> at +""" + +class Evaluator: Context { + var program: [String: Signal] + var stack: [String] = [] + + init(_ program: [String: Signal]) { + self.program = program + } + + func evaluate(_ signal: String) throws -> UInt16 { + guard !stack.contains(signal) else { + throw EvaluationError.circularDefinition(signal) + } + stack.append(signal) + defer { stack.removeLast() } + + guard let def = program[signal] else { throw EvaluationError.signalMissing(signal) } + let result = try def.evaluate(context: self) + + program[signal] = .value(.value(result)) + + return result + } +} + +let scanner = Scanner(string: input) +var circuit = try scanner.circuit() +let evaluator = Evaluator(circuit) +let a = try evaluator.evaluate("a") +print(a) + +circuit["b"] = .value(.value(a)) + +let otherEvaluator = Evaluator(circuit) +let newA = try otherEvaluator.evaluate("a") + +print(newA) diff --git a/2015/Day8.playground/Contents.swift b/2015/Day8.playground/Contents.swift new file mode 100644 index 0000000..72c39ff --- /dev/null +++ b/2015/Day8.playground/Contents.swift @@ -0,0 +1,393 @@ +let input = #""" +"sjdivfriyaaqa\xd2v\"k\"mpcu\"yyu\"en" +"vcqc" +"zbcwgmbpijcxu\"yins\"sfxn" +"yumngprx" +"bbdj" +"czbggabkzo\"wsnw\"voklp\"s" +"acwt" +"aqttwnsohbzian\"evtllfxwkog\"cunzw" +"ugvsgfv" +"xlnillibxg" +"kexh\"pmi" +"syvugow" +"m\"ktqnw" +"yrbajyndte\\rm" +"f\"kak\x70sn\xc4kjri" +"yxthr" +"alvumfsjni\"kohg" +"trajs\x5brom\xf1yoijaumkem\"\"tahlzs" +"\"oedr\"pwdbnnrc" +"qsmzhnx\"" +"\"msoytqimx\\tbklqz" +"mjdfcgwdshrehgs" +"\"rivyxahf\"" +"ciagc\x04bp" +"xkfc" +"xrgcripdu\x4c\xc4gszjhrvumvz\"mngbirb" +"gvmae\"yiiujoqvr\"mkxmgbbut\"u" +"ih" +"ncrqlejehs" +"mkno\x43pcfdukmemycp" +"uanzoqxkpsksbvdnkji\"feamp" +"axoufpnbx\\ao\x61pfj\"b" +"dz\\ztawzdjy" +"ihne\"enumvswypgf" +"\"dgazthrphbshdo\\vuqoiy\"" +"dlnmptzt\\zahwpylc\\b\"gmslrqysk" +"mhxznyzcp" +"rebr\"amvxw\x5fmbnfpkkeghlntavj" +"lades\x47ncgdof\"\"jmbbk" +"dwxuis\xa5wdkx\\z\"admgnoddpgkt\\zs" +"g\\k\x27qsl\x34hwfglcdxqbeclt\xca\\" +"lhyjky\\m\"pvnm\\xmynpxnlhndmahjl" +"c\"uxabbgorrpprw\"xas\\vefkxioqpt" +"rfrvjxpevcmma\x71gtfipo" +"fgh\"kcwoqwfnjgdlzfclprg\"q" +"onxnwykrba" +"hkkg\x60f\"tjzsanpvarzgkfipl" +"\"aintes\"ofq\"juiaqlqxmvpe\\a" +"wiyczzs\"ciwk" +"mfqeu" +"v\xe1z\x7ftzalmvdmncfivrax\\rjwq" +"k\"vtg" +"exhrtdugeml\xf0" +"behnchkpld" +"mhgxy\"mfcrg\xc5gnp\"\"osqhj" +"rlvjy" +"awe" +"ctwy" +"vt" +"\x54t" +"zugfmmfomz" +"cv\"cvcvfaada\x04fsuqjinbfh\xa9cq\xd2c\"d" +"oj" +"xazanf\"wbmcrn" +"\\\\zkisyjpbzandqikqjqvee" +"dpsnbzdwnxk\\v" +"sj\"tuupr\\oyoh" +"myvkgnw\x81q\xaaokt\\emgejbsyvxcl\\\xee" +"ejeuqvunjcirdkkpt\"nlns" +"twmlvwxyvfyqqzu" +"\"xwtzdp\x98qkcis\"dm\\\"ep\"xyykq" +"vvcq\\expok" +"wgukjfanjgpdjb" +"\"mjcjajnxy\\dcpc" +"wdvgnecw\\ab\x44klceduzgsvu" +"dqtqkukr\"iacngufbqkdpxlwjjt" +"\"xj\"\x66qofsqzkoah" +"nptiwwsqdep" +"gsnlxql\x30mjl" +"yeezwokjwrhelny\"" +"bjauamn\\izpmzqqasid" +"tvjdbkn\"tiziw\x82r" +"w" +"xwoakbbnjnypnaa\xa9wft\"slrmoqkl" +"vwxtnlvaaasyruykgygrvpiopzygf\"vq" +"qdancvnvmhlmpj\\isdxs" +"xzc\\elw" +"b\"wxeqvy\"qf\"g\xcaoklsucwicyw\"dovr" +"yomlvvjdbngz\"rly\"afr" +"bfb\"x\"aweuwbwmoa\x13\"t\"zhr" +"\"dmfoxb\"qvpjzzhykt\xd2\"\"ryhxi" +"psqef\"yu\\qiflie\"\x79w" +"arzewkej\"lqmh\\sayyusxxo\\" +"vuvvp" +"hc\"lg\x6bcpupsewzklai\"l" +"cjdfygc\"auorqybnuqghsh\x10" +"j" +"wqjexk\"eyq\\lbroqhk\\dqzsqk" +"dws\"ru\"dvxfiwapif\"oqwzmle" +"agcykg\\jt\\vzklqjvknoe" +"kksd\"jmslja\\z\"y\\b\xaagpyojct" +"nnpipxufvbfpoz\"jno" +"dtw" +"xlolvtahvgqkx\\dgnhj\\spsclpcxv\\" +"mxea\\mbjpi" +"lgbotkk\"zmxh\\\\qji\"jszulnjsxkqf" +"lwckmhwhx\"gmftlb\x91am" +"xxdxqyxth" +"\"lmqhwkjxmvayxy" +"tf" +"qy" +"wdqmwxdztax\"m\"\x09\x11xdxmfwxmtqgwvf" +"\xcbnazlf\"ghziknszmsrahaf" +"e\x6aupmzhxlvwympgjjpdvo\"kylfa" +"\x81vhtlillb\xactgoatva" +"dvnlgr" +"f" +"xg\xfacwizsadgeclm" +"vnnrzbtw\"\\prod\\djbyppngwayy\"" +"lrt\xf4jahwvfz" +"aqpnjtom\"ymkak\\dadfybqrso\\fwv" +"gz\"aac\"mrbk\"ktommrojraqh" +"wycamwoecsftepfnlcdkm" +"nrhddblbuzlqsl\x9cben" +"vckxhyqkmqmdseazcykrbysm" +"sil\xbbtevmt\"gvrvybui\"faw\"j" +"cjex\\tp\x45pzf" +"asjobvtxszfodgf\"ibftg" +"gkyjyjdrxdcllnh\"sjcibenrdnxv" +"oswsdpjyxpbwnqbcpl\"yrdvs\\zq" +"\"\"tyowzc\\fycbp\"jbwrbvgui" +"cbpcabqkdgzmpgcwjtrchxp" +"iyrzfh\x45gw\"fdlfpiaap\x31xqq" +"evgksznidz" +"b\\w\\" +"loufizbiy\x57aim\"bgk" +"qjfyk" +"g\"anmloghvgr\x07zwqougqhdz" +"usbbmwcxd\\bdgg" +"htitqcpczml" +"eke\\cqvpexqqk\"to\"tqmljrpn\xe6lji\"" +"g\xd2ifdsej" +"h\"sk\"haajajpagtcqnzrfqn\xe6btzo" +"wfkuffdxlvm\\cvlyzlbyunclhmpp" +"myaavh\"spue" +"hqvez\x68d\"eo\"eaioh" +"s\"qd\"oyxxcglcdnuhk" +"ilqvar" +"srh" +"puuifxrfmpc\"bvalwi\x2blu\\" +"yywlbutufzysbncw\\nqsfbhpz\"mngjq" +"zbl\\jfcuop" +"hjdouiragzvxsqkreup\\" +"qi" +"ckx\\funlj\xa7ahi" +"k" +"ufrcnh\"ajteit" +"cqv\"bgjozjj\x60x\xa8yhvmdvutchjotyuz" +"hkuiet\"oku\x8cfhumfpasl" +"\"\\sbe\x4d" +"vhknazqt" +"eyyizvzcahgflvmoowvs\\jhvygci" +"kki\x3ewcefkgtjap\"xtpxh\"lzepoqj" +"wvtk" +"\"ynet" +"zh\\obk\"otagx\x59txfzf" +"ocowhxlx\xe6zqg\x63wx\\tclkhq\\vmaze" +"w\"cf" +"qpniprnrzrnvykghqnalr" +"jctcqra\"\x05dhlydpqamorqjsijt\\xjdgt" +"sig" +"qhlbidbflwxe\"xljbwls\x20vht" +"irmrebfla\xefsg\"j" +"nep" +"hjuvsqlizeqobepf" +"guzbcdp\"obyh" +"\"mjagins\xf9tqykaxy\"" +"knvsdnmtr\"zervsb" +"hzuy" +"zza\"k\"buapb\\elm\xfeya" +"lrqar\"dfqwkaaqifig\"uixjsz" +"\"azuo\x40rmnlhhluwsbbdb\x32pk\\yu\"pbcf" +"dplkdyty" +"rfoyciebwlwphcycmguc" +"ivnmmiemhgytmlprq\\eh" +"lhkyzaaothfdhmbpsqd\\yyw" +"tnlzifupcjcaj" +"\\qiyirsdrfpmu\\\x15xusifaag" +"\\lcomf\\s" +"uramjivcirjhqcqcg" +"kkbaklbxfxikffnuhtu\xc6t\"d" +"n\xefai" +"\"toy\"bnbpevuzoc\"muywq\"gz\"grbm" +"\"muu\\wt" +"\\srby\"ee" +"erf\"gvw\"swfppf" +"pbqcgtn\"iuianhcdazfvmidn\\nslhxdf" +"uxbp" +"up\\mgrcyaegiwmjufn" +"nulscgcewj\\dvoyvhetdegzhs\"" +"masv\"k\\rzrb" +"qtx\x79d\"xdxmbxrvhj" +"fid\\otpkgjlh\"qgsvexrckqtn\xf4" +"tagzu" +"bvl\\\"noseec" +"\\xgicuuh" +"w\"a\"npemf" +"sxp" +"nsmpktic\x8awxftscdcvijjobnq\"gjd" +"uks\"\"jxvyvfezz\"aynxoev\"cuoav" +"m" +"lkvokj" +"vkfam\"yllr\"q\x92o\x4ebecnvhshhqe\\" +"efdxcjkjverw" +"lmqzadwhfdgmep\x02tzfcbgrbfekhat" +"cpbk\x9azqegbpluczssouop\x36ztpuoxsw" +"cqwoczxdd\"erdjka" +"cwvqnjgbw\\fxdlby" +"mvtm" +"lt\"bbqzpumplkg" +"ntd\xeeuwweucnuuslqfzfq" +"y\xabl\"dbebxjrlbmuoo\\\x1au" +"qjoqx\\a" +"pu\"ekdnfpmly\xbago\"" +"fjhhdy" +"arl" +"xcywisim\"bwuwf\"\"raepeawwjub" +"pbe" +"dbnqfpzyaumxtqnd\xc5dcqrkwyop" +"ojv\x40vtkwgkqepm\x8bzft\\vedrry" +"wggqkfbwqumsgajqwphjec\"mstxpwz" +"zjkbem" +"icpfqxbelxazlls" +"pvpqs\\abcmtyielugfgcv\"tjxapxqxnx" +"oqddwlvmtv\"\x39lyybylfb\"jmngnpjrdw" +"gisgbve" +"\"aglg" +"y\"\"ss\xafvhxlrjv" +"qbgqjsra" +"ihshbjgqpdcljpmdwdprwloy" +"djja\\wcdn\"svkrgpqn\"uz\"hc\x43hj" +"cbjm" +"pnn" +"pqvh\"noh" +"\"\\fdktlp" +"ncea" +"pqgzphiyy" +"\xbedovhxuipaohlcvkwtxwmpz\"ckaif\"r" +"arjuzbjowqciunfwgxtph\"vlhy\"n" +"c" +"nrpdxunulgudqzlhtae" +"iefheu\"uru\"" +"aqijysxuijud\"np\\opbichhudil\xbesum" +"pfpevmtstl\"lde\"bzr\"vspdxs" +"vparfbdjwvzsocpnzhp" +"g\x4ffxaarafrsjthq\\\xc1rw" +"ng\\rqx\\gwpzucbh\xafl" +"rw\"nf\\dna" +"jkkeahxurxla\\g\xb3czrlsyimmwcwthr" +"twaailoypu\"oas\"kpuuyedlaw\\\xb0vzt" +"hznex\\gdiqvtugi" +"imdibsunjeswhk" +"ta\\icileuzpxro\"cfmv\"mzp" +"coykr\x57luiysucfaflmilhlehmvzeiepo" +"u\x3dfh\xd4yt" +"piw\x1bz\"eowy\"vfk\"wqiekw" +"gan\"y" +"p\"bevidoazcznr\"hddxuuq\"" +"bwzucczznutbxe" +"z\"viqgyqjisior\\iecosmjbknol" +"dmlpcglcfkfsctxydjvayhymv\x3c\\gp" +"bfvkqrintbbvgfv" +"xlzntrgdck\"cprc\xadczyarbznqmuhxyuh" +"uqdxnuwioc\"kdytxq\\ig" +"xrafmucpmfi" +"vr\"hltmfrge" +"eonf\"nt\\wtcnsocs" +"j\xb7xoslyjeyjksplkqixncgkylkw" +"njw\"pefgfbez\x9axshdmplxzquqe" +"di\x58bvptfsafirpc" +"l\x1fkco" +"x" +"mprndo\"n" +"psegit" +"svbdnkkuuqs\"sqxu\"oqcyz\"aizashk" +"cwkljukxer\\\"\\nff\"esjwiyaoy" +"ilxrkgbjjxpvhdtq\"cpiuoofdnkpp" +"hlngi\"ulxep\\qohtmqnqjb\"rkgerho" +"gxws\"bcgm\"p" +"bv\"mds\\zhfusiepgrz\\b\x32fscdzz" +"l\xfampwtme\x69qvxnx\"\"\xc4jruuymjxrpsv" +"qqmxhrn" +"xziq\\\x18ybyv\x9am\"neacoqjzytertisysza" +"aqcbvlvcrzceeyx\\j\"\"x" +"yjuhhb" +"\x5em\"squulpy" +"dpbntplgmwb" +"utsgfkm\\vbftjknlktpthoeo" +"ccxjgiocmuhf\"ycnh" +"lltj\"kbbxi" +"""# + +extension String { + var lines: AnySequence { + AnySequence(sequence(state: self[...]) { rest in + guard !rest.isEmpty else { return nil } + + if let lineEnd = rest.firstIndex(where: \.isNewline) { + + let result = rest[.. Int { + guard hasPrefix(#"""#), hasSuffix(#"""#) else { + preconditionFailure() + } + + var count = 0 + var mode = Mode.regular + + for char in dropFirst().dropLast() { + switch mode { + case .regular where char == "\\": + mode = .escapeStart + + case .regular: + count += 1 + + case .escapeStart where char == "x": + mode = .hexDigit1 + + case .escapeStart: + count += 1 + mode = .regular + + case .hexDigit1: + mode = .hexDigit2 + + case .hexDigit2: + mode = .regular + count += 1 + } + } + + return count + } +} + +let result: Int = input.lines + .map { $0.count - $0.decodedLength() } + .reduce(0) { $0 + $1 } + +extension StringProtocol { + func encode() -> String { + var result = #"""# + + for char in self { + switch char { + case #"""#: result += #"\""# + case "\\": result += "\\\\" + default: result.append(char) + } + } + + result += #"""# + return result + } +} + +let result2: Int = input.lines + .map { $0.encode().count - $0.count } + .reduce(0) { $0 + $1 } diff --git a/2015/Day8.playground/contents.xcplayground b/2015/Day8.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day8.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day8.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day8.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day8.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/2015/Day9.playground/Contents.swift b/2015/Day9.playground/Contents.swift new file mode 100644 index 0000000..9282eda --- /dev/null +++ b/2015/Day9.playground/Contents.swift @@ -0,0 +1,69 @@ +var input: [(from: String, to: String, distance: Int)] = [ + ("Tristram", "AlphaCentauri", 34), + ("Tristram", "Snowdin", 100), + ("Tristram", "Tambi", 63), + ("Tristram", "Faerun", 108), + ("Tristram", "Norrath", 111), + ("Tristram", "Straylight", 89), + ("Tristram", "Arbre", 132), + ("AlphaCentauri", "Snowdin", 4), + ("AlphaCentauri", "Tambi", 79), + ("AlphaCentauri", "Faerun", 44), + ("AlphaCentauri", "Norrath", 147), + ("AlphaCentauri", "Straylight", 133), + ("AlphaCentauri", "Arbre", 74), + ("Snowdin", "Tambi", 105), + ("Snowdin", "Faerun", 95), + ("Snowdin", "Norrath", 48), + ("Snowdin", "Straylight", 88), + ("Snowdin", "Arbre", 7), + ("Tambi", "Faerun", 68), + ("Tambi", "Norrath", 134), + ("Tambi", "Straylight", 107), + ("Tambi", "Arbre", 40), + ("Faerun", "Norrath", 11), + ("Faerun", "Straylight", 66), + ("Faerun", "Arbre", 144), + ("Norrath", "Straylight", 115), + ("Norrath", "Arbre", 135), + ("Straylight", "Arbre", 127), +] + +var distances: [String: [String: Int]] = input.reduce(into: [:]) { result, input in + let (from, to, distance) = input + + result[from, default: [:]][to] = distance + result[to, default: [:]][from] = distance +} + +func totalDistance(route: [String]) -> Int { + var distance = 0 + var current = route[0] + for place in route.dropFirst() { + distance += distances[current]![place]! + current = place + } + + return distance +} + +func combinations(_ s: Set) -> [[String]] { + if s.count <= 2 { + return [Array(s)] + } + + return s.reduce([]) { result, first in + let rest = s.subtracting([first]) + + return result + combinations(rest).map { sub in + var result = [first] + result.append(contentsOf: sub) + return result + } + } +} + +combinations(Set(distances.keys)) + .map { totalDistance(route: $0) } + .max() + diff --git a/2015/Day9.playground/contents.xcplayground b/2015/Day9.playground/contents.xcplayground new file mode 100644 index 0000000..cf026f2 --- /dev/null +++ b/2015/Day9.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/2015/Day9.playground/playground.xcworkspace/contents.xcworkspacedata b/2015/Day9.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ca3329e --- /dev/null +++ b/2015/Day9.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + +