This commit is contained in:
Sven Weidauer 2022-11-23 16:45:30 +01:00
parent c7deb3c71d
commit ddf5ec2274
56 changed files with 6756 additions and 1 deletions

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
*.xcodeproj/**/xcuserdata/
xcuserdata/
.DS_Store

View file

@ -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 = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
/* 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 = "<group>";
};
260EAFB92700573200842D82 /* Day16 */ = {
isa = PBXGroup;
children = (
260EAFBA2700573200842D82 /* main.swift */,
);
path = Day16;
sourceTree = "<group>";
};
26780D5226F7712800C44D54 = {
isa = PBXGroup;
children = (
26780D6126F7733C00C44D54 /* Day13 */,
260EAFAE27004F2300842D82 /* Day14 */,
260EAFB92700573200842D82 /* Day16 */,
26780D6026F7733C00C44D54 /* Products */,
);
sourceTree = "<group>";
};
26780D6026F7733C00C44D54 /* Products */ = {
isa = PBXGroup;
children = (
26780D5F26F7733C00C44D54 /* Day13 */,
260EAFAD27004F2300842D82 /* Day14 */,
260EAFB82700573200842D82 /* Day16 */,
);
name = Products;
sourceTree = "<group>";
};
26780D6126F7733C00C44D54 /* Day13 */ = {
isa = PBXGroup;
children = (
26780D6226F7733C00C44D54 /* main.swift */,
);
path = Day13;
sourceTree = "<group>";
};
/* 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 */;
}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

Binary file not shown.

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

View file

@ -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

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

View file

@ -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

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

188
2015/Day13/main.swift Normal file
View file

@ -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
}
}

View file

@ -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

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>

36
2015/Day14/main.swift Normal file
View file

@ -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)

571
2015/Day16/main.swift Normal file
View file

@ -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)

57
2015/Day17.swift Normal file
View file

@ -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)

153
2015/Day18.swift Normal file
View file

@ -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")

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

View file

@ -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()

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

View file

@ -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

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

View file

@ -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 = "<group>"; };
/* 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 = "<group>";
};
2628B52026EDF9EE00ECED43 /* Products */ = {
isa = PBXGroup;
children = (
2628B51F26EDF9EE00ECED43 /* Day6 */,
);
name = Products;
sourceTree = "<group>";
};
2628B52126EDF9EE00ECED43 /* Day6 */ = {
isa = PBXGroup;
children = (
2628B52226EDF9EE00ECED43 /* main.swift */,
);
path = Day6;
sourceTree = "<group>";
};
/* 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 */;
}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

433
2015/Day6/Day6/main.swift Normal file
View file

@ -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)

View file

@ -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 = "<group>"; };
/* 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 = "<group>";
};
2628B53326EE043900ECED43 /* Products */ = {
isa = PBXGroup;
children = (
2628B53226EE043900ECED43 /* Day7 */,
);
name = Products;
sourceTree = "<group>";
};
2628B53426EE043900ECED43 /* Day7 */ = {
isa = PBXGroup;
children = (
2628B53526EE043900ECED43 /* main.swift */,
);
path = Day7;
sourceTree = "<group>";
};
/* 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 */;
}

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

531
2015/Day7/Day7/main.swift Normal file
View file

@ -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>() -> 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)

View file

@ -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<Substring> {
AnySequence(sequence(state: self[...]) { rest in
guard !rest.isEmpty else { return nil }
if let lineEnd = rest.firstIndex(where: \.isNewline) {
let result = rest[..<lineEnd]
rest = rest[rest.index(after: lineEnd)...]
return result
} else {
let result = rest
rest = ""
return result
}
})
}
}
enum Mode {
case regular
case escapeStart
case hexDigit1
case hexDigit2
}
extension StringProtocol {
func decodedLength() -> 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 }

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

View file

@ -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>) -> [[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()

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>