Day 5 - 10

This commit is contained in:
Sven Weidauer 2021-12-12 11:21:58 +01:00
parent 8a50c9ab9d
commit 31d96b280a
11 changed files with 2506 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
xcuserdata/

View file

@ -0,0 +1,675 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 55;
objects = {
/* Begin PBXBuildFile section */
261F317F2763DACC0018D49C /* day10.swift in Sources */ = {isa = PBXBuildFile; fileRef = 261F317E2763DACC0018D49C /* day10.swift */; };
261F31802763DACE0018D49C /* common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 269BE5CB2762A08800871C85 /* common.swift */; };
263BA5B3275E97AA00839C92 /* day5part2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 263BA5B2275E97AA00839C92 /* day5part2.swift */; };
263BA5C0275EA5BD00839C92 /* day6.swift in Sources */ = {isa = PBXBuildFile; fileRef = 263BA5BF275EA5BD00839C92 /* day6.swift */; };
269BE5BC2762959C00871C85 /* day8part2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 269BE5BB2762959B00871C85 /* day8part2.swift */; };
269BE5CA2762A05300871C85 /* day9.swift in Sources */ = {isa = PBXBuildFile; fileRef = 269BE5C82762A04F00871C85 /* day9.swift */; };
269BE5CC2762A08800871C85 /* common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 269BE5CB2762A08800871C85 /* common.swift */; };
269BE5CD2762A08800871C85 /* common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 269BE5CB2762A08800871C85 /* common.swift */; };
269BE5CE2762A08800871C85 /* common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 269BE5CB2762A08800871C85 /* common.swift */; };
269BE5CF2762A08800871C85 /* common.swift in Sources */ = {isa = PBXBuildFile; fileRef = 269BE5CB2762A08800871C85 /* common.swift */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
261F31752763DAB60018D49C /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
263BA5A9275E978400839C92 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
263BA5B6275EA5A600839C92 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
269BE5B22762958800871C85 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
269BE5BF2762A03F00871C85 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
261F31772763DAB60018D49C /* Day10 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Day10; sourceTree = BUILT_PRODUCTS_DIR; };
261F317E2763DACC0018D49C /* day10.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = day10.swift; sourceTree = "<group>"; };
263BA5AB275E978400839C92 /* Day5Part2 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Day5Part2; sourceTree = BUILT_PRODUCTS_DIR; };
263BA5B2275E97AA00839C92 /* day5part2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = day5part2.swift; sourceTree = "<group>"; };
263BA5B8275EA5A600839C92 /* Day6 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Day6; sourceTree = BUILT_PRODUCTS_DIR; };
263BA5BF275EA5BD00839C92 /* day6.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = day6.swift; sourceTree = "<group>"; };
269BE5B42762958800871C85 /* Day8Part2 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Day8Part2; sourceTree = BUILT_PRODUCTS_DIR; };
269BE5BB2762959B00871C85 /* day8part2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = day8part2.swift; sourceTree = "<group>"; };
269BE5C12762A03F00871C85 /* Day9 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Day9; sourceTree = BUILT_PRODUCTS_DIR; };
269BE5C82762A04F00871C85 /* day9.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = day9.swift; sourceTree = "<group>"; };
269BE5CB2762A08800871C85 /* common.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = common.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
261F31742763DAB60018D49C /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
263BA5A8275E978400839C92 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
263BA5B5275EA5A600839C92 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
269BE5B12762958800871C85 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
269BE5BE2762A03F00871C85 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
263BA594275E974800839C92 = {
isa = PBXGroup;
children = (
261F317E2763DACC0018D49C /* day10.swift */,
269BE5CB2762A08800871C85 /* common.swift */,
269BE5C82762A04F00871C85 /* day9.swift */,
269BE5BB2762959B00871C85 /* day8part2.swift */,
263BA5BF275EA5BD00839C92 /* day6.swift */,
263BA5B2275E97AA00839C92 /* day5part2.swift */,
263BA59E275E974800839C92 /* Products */,
);
sourceTree = "<group>";
};
263BA59E275E974800839C92 /* Products */ = {
isa = PBXGroup;
children = (
263BA5AB275E978400839C92 /* Day5Part2 */,
263BA5B8275EA5A600839C92 /* Day6 */,
269BE5B42762958800871C85 /* Day8Part2 */,
269BE5C12762A03F00871C85 /* Day9 */,
261F31772763DAB60018D49C /* Day10 */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
261F31762763DAB60018D49C /* Day10 */ = {
isa = PBXNativeTarget;
buildConfigurationList = 261F317D2763DAB60018D49C /* Build configuration list for PBXNativeTarget "Day10" */;
buildPhases = (
261F31732763DAB60018D49C /* Sources */,
261F31742763DAB60018D49C /* Frameworks */,
261F31752763DAB60018D49C /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = Day10;
productName = Day10;
productReference = 261F31772763DAB60018D49C /* Day10 */;
productType = "com.apple.product-type.tool";
};
263BA5AA275E978400839C92 /* Day5Part2 */ = {
isa = PBXNativeTarget;
buildConfigurationList = 263BA5AF275E978400839C92 /* Build configuration list for PBXNativeTarget "Day5Part2" */;
buildPhases = (
263BA5A7275E978400839C92 /* Sources */,
263BA5A8275E978400839C92 /* Frameworks */,
263BA5A9275E978400839C92 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = Day5Part2;
productName = Day5Part2;
productReference = 263BA5AB275E978400839C92 /* Day5Part2 */;
productType = "com.apple.product-type.tool";
};
263BA5B7275EA5A600839C92 /* Day6 */ = {
isa = PBXNativeTarget;
buildConfigurationList = 263BA5BC275EA5A600839C92 /* Build configuration list for PBXNativeTarget "Day6" */;
buildPhases = (
263BA5B4275EA5A600839C92 /* Sources */,
263BA5B5275EA5A600839C92 /* Frameworks */,
263BA5B6275EA5A600839C92 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = Day6;
productName = Day6;
productReference = 263BA5B8275EA5A600839C92 /* Day6 */;
productType = "com.apple.product-type.tool";
};
269BE5B32762958800871C85 /* Day8Part2 */ = {
isa = PBXNativeTarget;
buildConfigurationList = 269BE5BA2762958800871C85 /* Build configuration list for PBXNativeTarget "Day8Part2" */;
buildPhases = (
269BE5B02762958800871C85 /* Sources */,
269BE5B12762958800871C85 /* Frameworks */,
269BE5B22762958800871C85 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = Day8Part2;
productName = Day8Part2;
productReference = 269BE5B42762958800871C85 /* Day8Part2 */;
productType = "com.apple.product-type.tool";
};
269BE5C02762A03F00871C85 /* Day9 */ = {
isa = PBXNativeTarget;
buildConfigurationList = 269BE5C52762A03F00871C85 /* Build configuration list for PBXNativeTarget "Day9" */;
buildPhases = (
269BE5BD2762A03F00871C85 /* Sources */,
269BE5BE2762A03F00871C85 /* Frameworks */,
269BE5BF2762A03F00871C85 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = Day9;
productName = Day9;
productReference = 269BE5C12762A03F00871C85 /* Day9 */;
productType = "com.apple.product-type.tool";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
263BA595275E974800839C92 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1310;
LastUpgradeCheck = 1310;
TargetAttributes = {
261F31762763DAB60018D49C = {
CreatedOnToolsVersion = 13.1;
LastSwiftMigration = 1310;
};
263BA5AA275E978400839C92 = {
CreatedOnToolsVersion = 13.1;
LastSwiftMigration = 1310;
};
263BA5B7275EA5A600839C92 = {
CreatedOnToolsVersion = 13.1;
LastSwiftMigration = 1310;
};
269BE5B32762958800871C85 = {
CreatedOnToolsVersion = 13.1;
LastSwiftMigration = 1310;
};
269BE5C02762A03F00871C85 = {
CreatedOnToolsVersion = 13.1;
};
};
};
buildConfigurationList = 263BA598275E974800839C92 /* Build configuration list for PBXProject "AoC21" */;
compatibilityVersion = "Xcode 13.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 263BA594275E974800839C92;
productRefGroup = 263BA59E275E974800839C92 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
263BA5AA275E978400839C92 /* Day5Part2 */,
263BA5B7275EA5A600839C92 /* Day6 */,
269BE5B32762958800871C85 /* Day8Part2 */,
269BE5C02762A03F00871C85 /* Day9 */,
261F31762763DAB60018D49C /* Day10 */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
261F31732763DAB60018D49C /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
261F31802763DACE0018D49C /* common.swift in Sources */,
261F317F2763DACC0018D49C /* day10.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
263BA5A7275E978400839C92 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
269BE5CC2762A08800871C85 /* common.swift in Sources */,
263BA5B3275E97AA00839C92 /* day5part2.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
263BA5B4275EA5A600839C92 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
269BE5CD2762A08800871C85 /* common.swift in Sources */,
263BA5C0275EA5BD00839C92 /* day6.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
269BE5B02762958800871C85 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
269BE5CE2762A08800871C85 /* common.swift in Sources */,
269BE5BC2762959C00871C85 /* day8part2.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
269BE5BD2762A03F00871C85 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
269BE5CF2762A08800871C85 /* common.swift in Sources */,
269BE5CA2762A05300871C85 /* day9.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
261F317B2763DAB60018D49C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 722B335UM5;
ENABLE_HARDENED_RUNTIME = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
261F317C2763DAB60018D49C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 722B335UM5;
ENABLE_HARDENED_RUNTIME = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Release;
};
263BA5A2275E974800839C92 /* 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 = 12.0;
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;
};
263BA5A3275E974800839C92 /* 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 = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
};
name = Release;
};
263BA5B0275E978400839C92 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 722B335UM5;
ENABLE_HARDENED_RUNTIME = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
263BA5B1275E978400839C92 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 722B335UM5;
ENABLE_HARDENED_RUNTIME = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Release;
};
263BA5BD275EA5A600839C92 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 722B335UM5;
ENABLE_HARDENED_RUNTIME = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
263BA5BE275EA5A600839C92 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 722B335UM5;
ENABLE_HARDENED_RUNTIME = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Release;
};
269BE5B82762958800871C85 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 722B335UM5;
ENABLE_HARDENED_RUNTIME = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
269BE5B92762958800871C85 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 722B335UM5;
ENABLE_HARDENED_RUNTIME = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Release;
};
269BE5C62762A03F00871C85 /* 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;
};
269BE5C72762A03F00871C85 /* 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 */
261F317D2763DAB60018D49C /* Build configuration list for PBXNativeTarget "Day10" */ = {
isa = XCConfigurationList;
buildConfigurations = (
261F317B2763DAB60018D49C /* Debug */,
261F317C2763DAB60018D49C /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
263BA598275E974800839C92 /* Build configuration list for PBXProject "AoC21" */ = {
isa = XCConfigurationList;
buildConfigurations = (
263BA5A2275E974800839C92 /* Debug */,
263BA5A3275E974800839C92 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
263BA5AF275E978400839C92 /* Build configuration list for PBXNativeTarget "Day5Part2" */ = {
isa = XCConfigurationList;
buildConfigurations = (
263BA5B0275E978400839C92 /* Debug */,
263BA5B1275E978400839C92 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
263BA5BC275EA5A600839C92 /* Build configuration list for PBXNativeTarget "Day6" */ = {
isa = XCConfigurationList;
buildConfigurations = (
263BA5BD275EA5A600839C92 /* Debug */,
263BA5BE275EA5A600839C92 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
269BE5BA2762958800871C85 /* Build configuration list for PBXNativeTarget "Day8Part2" */ = {
isa = XCConfigurationList;
buildConfigurations = (
269BE5B82762958800871C85 /* Debug */,
269BE5B92762958800871C85 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
269BE5C52762A03F00871C85 /* Build configuration list for PBXNativeTarget "Day9" */ = {
isa = XCConfigurationList;
buildConfigurations = (
269BE5C62762A03F00871C85 /* Debug */,
269BE5C72762A03F00871C85 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 263BA595275E974800839C92 /* 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>

18
common.swift Normal file
View file

@ -0,0 +1,18 @@
protocol Puzzle {
mutating func run()
init()
}
extension Puzzle {
static func main() {
var instance = Self()
instance.run()
}
}
extension RangeReplaceableCollection {
mutating func removeFirst(where predicate: (Element) -> Bool) -> Element? {
guard let index = firstIndex(where: predicate) else { return nil }
return remove(at: index)
}
}

170
day10.swift Normal file
View file

@ -0,0 +1,170 @@
@main
struct Day10: Puzzle {
func run() {
var rest = input[...]
var score = 0
var completeionScores: [Int] = []
loop: while true {
if let complete = parse(&rest) {
completeionScores.append(complete)
}
switch rest.first {
case "\n": break
case ")": score += 3
case "]": score += 57
case "}": score += 1197
case ">": score += 25137
case let ch?: print("Unknown char", ch)
case nil: break loop
}
rest = rest.drop { !$0.isNewline }.dropFirst()
}
print(score)
completeionScores.sort()
let completeScore = completeionScores[completeionScores.count / 2]
print("Part 2:", completeScore)
}
func end(for start: Character) -> Character? {
switch start {
case "(": return ")"
case "[": return "]"
case "{": return "}"
case "<": return ">"
default: return nil
}
}
func parse(_ string: inout Substring) -> Int? {
var stack: [Character] = []
while true {
guard let current = string.first else { return nil }
if current == stack.last {
stack.removeLast()
} else if let closing = end(for: current) {
stack.append(closing)
} else if current == "\n" {
return stack.reversed().reduce(0) { partialResult, ch -> Int in
let characterScore: Int
switch (ch) {
case ")": characterScore = 1
case "]": characterScore = 2
case "}": characterScore = 3
case ">": characterScore = 4
default: fatalError()
}
return partialResult * 5 + characterScore
}
} else { return nil }
string = string.dropFirst()
}
}
let input = """
{<[[<<<[[{[[<<()()>>[([]<>){{}{}}]]]<(<{{}<>}{{}{}}><{<>[]}[{}{}]>)({(())}<[(){}][(){}]>)>}]<<<(<<{}
{[({({([({(((<[]()>[()<>]){[<>[]](<>[])})<<<[]()}>(<()()>)>)}[{((<{}[]>{<>()}){[<>{}]<<><>>})(({[]()}<<>()>)<
(((([{{{<{<[[<()<>><<>{}>]]{<(<>())>}>{<[([]<>)<{}{}>][[<><>][<>[]]]>[{(<>{})[<>()]}<<()[]>[[]<
<<[<([[{{{[({<<>()>}<<<>[]>([]())>){{{{}[]}<(){}>)}]{{[(()())[(){}]]<<[]{}>({}[])>}({<<><>>}<([]<>){()[]}>)}
<[(({[({<<[[[{<>{}}(<><>))<(<>[])[{}[]]>]<[([][])[(){}]]>]([<[()()](<>[])>]<(<{}()>[{}<>])({<>[
(<[[{[[[(<((<<{}{}><[]<>>><[{}<>][<>[]]>)<(<{}<>><{}{}>)[{()[]}<<>()>]>)>[(<{({}{})}[{()[]}{[]<>}]>){<(([]
(([[({{{(<([({[]{}}){{[][]]}])>)[<([[[{}]{(){}}][([]())]]([{[][]}{<>()}](({}()){<>{}})))[{({
{(<<([([(<<[{((){})([]<>)}]<{{{}{}}{{}[]}}<{(){}}{()[]})>><([<[]{}>([]<>)](<()<>>)){<([]<>
{[<<[<{{((({<[[]{}]{{}}>{<{}<>>[<>[]]}})<{[(<><>><{}<>>][{[]{}}]}[[[[][]]<<>{}>]{[[]()][[]<>]}]>)[(
({<(<([{<{<[(((){}){(){}})]>}[{{{{()()}<[]()>}{{<>()}<{}{}>}}[[{{}{}}[<><>]]{({}[]>[[]{}]}]}({{{()()
{[[{([{<<{<(<<{}()>[()]>)<{{()()}}[<[][]>(<>{})]>>{[<{<>()){()<>}>{{()()}[<>()]}][[[{}[]]]<{{}[]}<()(
{{<<<<<[[([{<[{}[]]{()<>}>{<<>()>{{}<>}}}<<{{}()}{()()}>{[()<>]({}[])]>]{[(<{}{}>)<({}[])>]<{({}<>)}{({}())
({(<<{[<<{<(<[<>()][[][]]><[{}<>]({}[])>)[[[<>[]][[]()]]<{[]{}}[{}{}]>]>{[(<[]()>{<>{}})][<{{}}<{
(<<<[[({<[[(<<[]{}>>[(()<>)[<>{}]])<{(<>[])}(<<>()>[[]{}])>]<[({[]()}{{}{}})<{{}()}<{}<>>>]>][[({<<>()>{[]()}
{{{[<[([<(<{[([][])[{}[]]]{[()()]{{}()}}}><[<([][])(<>())><{()[]}({}<>)>]<<<(){}><<><>>>((()()){
[(((([{({<(<(<[]<>>{()[]})><{(<><>){{}[]}}{(()<>)([][])}>)>})}][({{[[{<(<><>){{}()}>((<>()){<>[]
([{<{<({(<[(<({}<>)><{[]}[{}[]]>)(<[[][]]{[]{}}>{{[]}((){})})]{(((()){{}()})(([][])({}{})))[(<()[]><(
[([{{<{(<[{{((()())<[]{}>){{{}<>}<<><>>}}[<([]())>[(()[])<{}{}>]]}{[({(){}}{(){}])<<[]()>{{}()}>
(<[<{{[<<({<<{<><>}><<()[]>[<><>]>>}{[(((){}){()<>}}<<[]()>{(){}}>]{{{{}[]}[{}<>]}[{{}{}}<(){}>]}}){{({
<([([[<[({<<{{[][]}<{}[]>}<<()[]>[()<>]>>>})((<(<[[]]((){})>{([]()){<><>}})>)(<<<<[]<>>[[]()])>>([[
[<<{<(<<{{[({<<>()><{}[]>})<{[<>()](<><>)}[{{}()}{[]()}]>]}}({<[{<()<>>}[<<>>]]((<[][]>{[][
{{(<({[((<([({()<>})[{{}[]}(()<>))]{[{[]<>}][{()<>}]})([({<><>}{{}()})])>)({<(((()<>)(<><>)))>((
[(<{({[<{<[<([{}()](<>{}))>]([([[]<>]<()<>>){<()>}]{{[[]()]{{}{}}}[{[]}{{}<>}]})>}<([<[<<>[]>]{<(){}>{
[[[[<(<({<[[<{()}{{}[]}><[<><>]<()[]>>](<([]{})[{}]>)]>}<[{[[{(){}}]{(<><>)}][<<[][]>{(){}
{(({({[{{((<[([]())((){})]>){[{(<>[])}<([]{})[[]<>]>]({<()<>>[[]<>]}[<()>{<>[]}])})({<([[][]]((){}))([<>{}])
<(<(<<{[<<{<<[()[]][[]()]><([][])<{}()>>}}>[<<<<{}<>>>{[{}][{}{}]}>[<[()()]{{}[]}>[{[][]}([])]]>[[<<[][]>(
<<{{({<<(([{{([][])(()<>)}}(<<[]{}>>)])([{[(()[])]}<{{<><>}<[]<>>}[<{}<>><[]<>)]>]{{<[{}[]]
({[[[[(([[[{<({})([]())>{{<>{}}}}][[<<[]>[<>()]>]{[[[]<>][<>{}]]{[<>[]]}})][[<(<(){}>{()[]})><[[()[
(((((([{{{(<<(<>{}){<>}><(()[])<()[]>>>{[<{}<>>(<>())}<{{}()}>})((([(){}]{<>})[{[]{}}{{}[]
(([([(((<[(({[<>()]{[][]}})[{{[]()>[[]{}]}(<<>{}><{}<>>)]){[({[]}(<>[]))([()()][<>{}])]({({}
[(<({{([[<(((<<>()>[[]<>])({{}()}<()<>>))[[{[]()}<()<>>][{()()}<{}[]>]])>({(<({}{})<()[]}>[{()
{{{[([<{{{([<<<>{}>{()<>}>{<{}()><<><>>}]([{()}]))<{[<()()>{()[]}]{({}[])[<>()]}}>}}}({<(({({
[([([<[<(<[{{{<>()}{()[]}}({()[]}[{}<>])}{[{<>}]([[][]]<(){}>)}]>[[{<[<>()][{}()]>(((){}>[<>[]])}{{{<>(
{{[{{[[<{(<([[[][]]([]<>)])>)<{<<{<>()}[<>()]><((){})<<><>>>>([<<><>>(()<>)]([(){}}{[]<>}))}>}(({{{{[]}{
[[[[({[<({{[[(<><>)]{<<>[]>([]{})}]<[{[]}{()()}]([<>()]([]<>>)>}})>{{<([{<{}{}>{()}}])({<[<>()](<><>)>
{[({<[({[{[({[{}()][[]<>]}((()<>)<{}<>>))<[{{}}({}{})]>]{[<<<>[]>[[][]]>(({}[])(()[]))>{(([]{})({}[]))([
[<<([{{(<<[<[[{}[]]](<[]{}>[<>{}])>[[<{}[]>(<>[])]{([][])[()[]]}]][[{{()[]}[<>{}]}(<<>{}>[[]
<[(([{([([<{[[(){}]<<>{}>]}[[[()()]{{}<>}]]>[[{({}{})[()()]}([()()][<>[]])]{<[[]<>][[][]]>}]]{{<{[<>
[<[[[[([[{[[<[{}{}]([]<>)>[({}[])<[]<>>]][<{()()}[<>[]]>([[]]<<><>>)]]}([<{{{}[]}}{(()<>>({}[
<[<{[(<{({[<[[[][]]([][])]<([]){{}<>}>>[({<>{}}<[]>)]]([[([]{})[[]()]][[[]{}]({}{})]](<[{}<>
({[<([(<[[<([[(){}]<<>{}>])({[[]{}]<()[]>}<<[]<>>{[][]}>)>{<[<[]()><{}[]>]([<>()]({}[]))><(
({<<<{<({[[{[{<>{}}[<><>]]}{(({})[()()])<<()<>>([]{})>}]]]{<{{([[]<>](<>[]))[[{}()]({}())]}}>((<([{}<>])>{{<[
[{([{[[{{<{<[{[]()}<[]{}>]>({<{}[]>{<>[]}})}[(({{}<>}<{}<>]){[[]{}]({}[])})]>}}]({([[([<()()>{[]
<[{([([{[{<(([<>[]]{<>()})<{{}<>}>){([<><>])<(()[])<<>{}>>}><{{[{}<>]{<>}}[(())[()<>]]}<{[{}{}]{{}{}}}<{{}<>
[{<<([{{(((<{<<>()>[{}()]}>{<<<>[]><[]()>>}){[(([][])([]()))<{{}[]}[[]()]>][[{{}<>}({}{})]{({}{})(<
{({[((<([[[{{([])[()()]}({{}{}}))<(<[]<>>[()[]])>]<<([[]<>])<[<>()][[]<>]>>({[<><>]{{}[]}}({()[]
{[(<(<{[({[(<<[]>{<>{}}>[{<><>}([]())])(<[[][]]<()<>>>[(()[])])]<{[{()[]}[<>{}]]}[{<(){}>(<>{})}<<<>()>>]
(<{<[<({{{{([({}{})[[]{}]]({{}<>}<()[]}))}(<<{<>()}{()<>}>{[<>{}][()[]]}>{<<[][]>{<>()}><(<>{})<{}[]>>})}
{(<<{[({<<[(<{{}{}}<[]<>>>((<>())([]<>)))]>><<({<{[]<>}([]<>)>{[()()]}}<<{{}<>}<()()>>(<()()
<([([<(<[({[[({}()){()<>}](({}{})(<><>))][{({}<>)<{}{}>}{([]){(){}}}]})]>)<[[{<{{(()){<>[]}}({{}()}
<<<([{[({{{((<{}()>{()()})[[<>()]])[[[{}()]<{}()>]{{[]<>}{{}())}]}<<{<<>><<><>>}[{{}[]}(<><>)
<([<[<{[[[{[{[<><>][{}<>]}(<[]{}>)]}([{{<>()}<{}[]>}{([]<>)[(){}]}]<{((){})<[]()>}[<[]()><()[]>]>
[([[[[[({{[(<[{}<>]<{}()>><[<><>]{<>()}>)]}<{(<(()<>)<{}{}>>{{()<>}(()()}})}>})(<[<([<<>[]>((){})]([[]<>]<()
{(<[[{(((([[([{}()]<{}()))[({}{}){[]}]](<<<>[]>>([<>{}]))][(<({}{})<()[]>><<[]{}><{}[]>>)])(<([([][])[
({(([{{<{{{<[<<>[]>{()<>}][([][]){()<>}]>([<()>(<><>)]<{<><>}<[]>>)}<{[[<>[]][<>{}]]<{<>()}{[][]
{[([[[(([<{<{[[]<>]<<>()>}<<()()>([]{})>>[<<()[]>(<>())>[(()<>)]]}>]{{({{{{}[]}({})}<{{}<>}[[]()]>}((
[<([[<[{{{[[[<<>{}>]{<()[]>{[]<>}}]{([[]{}]({}()))}]}}}(<{<[[({}{})<()()>]]({({}<>)[[]]}{[<><>]{<>{}}})>(<[
<<(<<{{(({<[<<[]{}>{()()}}[[()[]]]]{[(<>{}){<>}]{[{}](<>)}}><{<(()())<[]<>>>[<(){}>(<>[])]
{<(<[<[(((<{((()[])([]<>))([[]<>]({}[]))}><<([<>())<[]<>>)(<{}[]>({}<>))>[[([]())]({()()}{{}<>})
[[((<[[[{{<{<{{}()}[{}()]>{{[]{}}[<><>]}}>}<{[<[(){}]<<><>>]([{}<>]<<><>>)]}(<<[{}<>]<<>{}>
<[{{[[{<[{(({[(){}]({}{})})[([{}<>][()()])[<[][]><{}<>>]])}](<({(([]<>){()[]})[([]())((){})]}{{{<>{}}<[]()>}<
<{((<([[{<<[(<{}()><{}[]>)]>[([{<>()}<()()>]<{()[]><()[]>>){<[{}[]]>[{[][]}(<><>)]}]>{{[{{{}<>}{<>}}[[(){}]<(
{<[({(<{{[([{{[]{}}((){})}[[{}[]]<{}()>]]((<[]<>>)<([]()){{}[]}>))(<<{()[]}{[]})>[[(()())]{[()<>][<>(
<<{[[[[{<({<[[{}()]]{{[]<>}{[]}}><{{{}()}({}{})}>}{([({}[])({}())](({}[])))[<{[]<>}[<>()]><<[]<>>(<>[])>]}
[(([<<[{[{<({{()[]}<<><>>})[[([]())[[]{}])(<<>{}>)]>(<{{[][]}[{}()]}([{}{}][(){}])>((<<>[]>(()
[({<<[[<{[<<({[]()}<()<>>)>]]{{<[[[]][{}<>]]>}{([[<>{}][{}{}]]<((){})(()[])>)}}}([{((<{}[]>)[<{}[]><{}()>])}
{[[((<[{<<([{<<><>>([]{})}<(<><>)<<>()>>][{[[]{}]{()()}}<({}{})([][])>])><<{({<>{}}[<>()])((
[[[<{{(<((([{<[]{}>({}<>)}[<<>()>]]<<(()[]){{}[]}>{(()<>){{}<>}}>){{{(()())[<><>]}[[[]<>]{<>[]}]}}))[
(<({[({[[({{<{<>{}}<()[]>>[{(){}}<<>[]>]}[[<[][]><()<>>]({<>{}}{[]()})]}{(([[]<>][{}[]])(<[]<>>([
{([<{[<({{{({[[][]][()()])[<<>()><[][]>])}<{{{[]()}[{}()]}{{<>()}{<>}}}((({}())<{}{}>){(<>{})[<>{}]})>}})(((
([[[[[[{(((((<<>()>[[]<>])<{()()}[()<>]>){<[()[]]<<>[]>>(<<>{}}{{}[]})}))<<[([()()][[]()])[{()[]}([]())]][<([
({{((((<{<[{[(<>{})][<()()>[[]()]]}]{({(<>())[[]()]}{<[][]><[][]>})}>}>{<<{{(({}())[<>])((()[])<[]<>>)}}[
<(<[[[<<{([<<[[]<>]{<>[]}><{()()}([]<>)>>]{<{(<>())((){})}{[{}{}]<<>{}>}>})({([[{}{}]])[(<<>()>[
{[(<{<[[{<{{(<()[]><<>{}>){[()<>]<{}<>>}}[[[<>{}][[]<>]]]}<[[({})<<>[]>]]{{<()<>><<>[]>}<{()[]}((){}
({[{(<<{[<{({[()()]{{}}}<({}{}){()()}>)}<{(({}{})[<>[]]){([]())[[][]]}}{(<[]<>)[()])[[<>()]]}>>
(({<<[<[<<<({<{}[]>({}{})}{<{}[]><{}[]>})>>(<<(<()()>{[]{}})({()<>}[()()])>[{[{}()][[]]}({<>()}}]>(
<<(<(<[{([{<[[<>{}]<{}<>>]>{<(()[])(()())><{<>[]}{()()}>}}([{({}<>){<>{}}}{{<>[]}[{}{}]}]([<[]()>((){})
{[{([({[[<<<{{[]{}}<[]{}>}[<()[]><[]<>>]>([{{}[]][[][]]]{{(){}}({}[])})>(<{[<>{}](()<>)}>{[<[]()>
([[[<(<{[({<({()()}{<>()})((<>[])<[]<>>)>}<{<<{}()><<>>>}({{{}[]}}[(()[])[()<>]])>)<[<((()())[<>{}])(
{<(((<[((((({<[]>[[]{}]}))[(<[[][]][{}{}]>){{[<>()][[]<>]}([()()](<><>))}])){(<[{[<>()][{}()]
({([{<(((<{[<[{}[]]<<>>>({{}[]}[[]()])]([<(){}>])}{<[{<>[]}{[]<>}][<<><>){<>{}}]>[<((){})([]{})>[[{}{}][()
<[{[<[{[({{<(({}<>}[[]()])>({{[][]}}<[(){}](()[])>)}})([[{{<<>()>([]{})}[<<>{}>[<><>]]}]])]
{(<{([{[[({[(<[]{}>)({{}[]}{()()}))<{(()[])}[[()()]{{}[]}]>}<{<(()<>)>{{[]{}}({}())}}({{{}[]}{<
[<<{<{<<(<([<(<>()){[]()}>[({}<>)({}<>)]][(([]{}){()[]})[{{}()}(()())]])>{([{{()[]}<<>[]>}<{<>[
{{[[(([([({([([]<>)(()())][{<>()}{(){}}])})])]([{{[<{{{}<>}(<>())>{[()()]<<>[]>}>[{(()){{}[
[({({({(({{(<[()()][{}<>]>[[{}()]{(){}}])<[<<>[]>][<{}>(<>{})]>}(((({}())({}{}))){{(()[])<[][
<(<(<[([<[{[<(()<>)<()[]>><(<>())([][])>]{<[{}<>]{{}()}>{[[]{}](<>{})}}}<[<([]{})><{{}<>}([]())>]>]>
<<<(<<[({{{<{({}<>)<()[]>}<[()<>]{(){}}>><{[[]()]<[]{}>}[({}{})<(){}>]>}(<[<<>[]>{()[]}]>)}[<{[<{}>[{}{
{(<((<[{{[[[[<{}{}]<{}()>]][{({}{})<<>{}>}[<()[]>(()())]]]{([<[]()><[]{}>](<{}()>))({<<><>>(<>())}{
{({{[[<[{<{{(<<>>)(<[]()>[()])}([({}<>)])}[[{[()<>][()[]]}]({<[]<>>{<>()}})]><<(<<{}()>{<>[]
{{{[{[<<{[[{[{{}<>}<[][]>]{(()[])<<>()>}}[<{()()}[(){}]><<()[]>>]]{<((<>{})({}()))[<(){}>([][])]>{({{}[]}<
<{{[<{({{{[<{{<>()}{{}()}}>]<{<[()[]](<><>)><[<>[]]{(){}}>}<([(){}]<{}{}>){(())}>>}[([{[[]<>][{}<>]}[{()}(
[<<[{{(({({<{{{}{}}{<>[]}}({[][]}{<>[]})>[{[{}<>][<>[]]}[({}[])[[]<>]]]})}))<(<[[<(({}()))[<<>()>{(
{<<([<{({[{{[({}[])<<>{}>]([()<>]<(){}>)}<([{}[]]({}{}))>}[<<<<>{}>[[][]]>{<<>[]><()>}>[<<<>><[][]>
[({(<({[<[{{[<<>[]>[()[]]]<<<>[]>>}}<{([{}[]](<>{}))[{<>}{{}<>}]}(<<[][]>>[{[]<>}])>]>[(<(({<>[]}{<><>}))(<
{<[[{{<<{(<(<([]<>)[[][]]>[([]{})[<>{}]])<[{<>()}{[]<>}]>>>[{(({()()}[<>[]]){({}())<[]<>>})}[(<{<>
{[[{{{<[<[{<(({}{})[{}()])[(<><>)({}())]>}{[<{[]{}}[()[]]>]<{[()()]<[]()>}<[[][]]>>}]>{{({{{()[]}{{}(
<{[<([{{[[<(<{<><>}[{}{}]><((){})>){[[()()][()[]]]{[[]<>]}}>]<<(<({}[])<{}[]>>{(<><>)<[]()>}){(<
"""
}

554
day5.hs Normal file
View file

@ -0,0 +1,554 @@
example :: [((Int, Int), (Int, Int))]
example = [
((0,9), (5,9)),
((8,0), (0,8)),
((9,4), (3,4)),
((2,2), (2,1)),
((7,0), (7,4)),
((6,4), (2,0)),
((0,9), (2,9)),
((3,4), (1,4)),
((0,0), (8,8)),
((5,5), (8,2))
]
isHorizontalOrVertical :: ((Int, Int), (Int, Int)) -> Bool
isHorizontalOrVertical ((x1, y1), (x2, y2)) = x1 == x2 || y1 == y2
atPoint (x,y) p = minX p <= x && x <= maxX p && minY p <= y && y <= maxY p
minX ((x1, _), (x2, _)) = min x1 x2
minY ((_, y1), (_, y2)) = min y1 y2
maxX ((x1, _), (x2, _)) = max x1 x2
maxY ((_, y1), (_, y2)) = max y1 y2
bounds :: (Ord b, Ord a) => [((a, b), (a, b))] -> ((a, b), (a, b))
bounds input = ((x0, y0), (x1, y1))
where
x0 = minimum $ map minX input
y0 = minimum $ map minY input
x1 = maximum $ map maxX input
y1 = maximum $ map maxY input
grid ((x0, y0), (x1, y1)) = [ (x, y) | x <- [x0..x1], y <- [y0..y1] ]
counts input = length $ filter (>= 2) intersectionCounts
where
intersectionCounts = map (\pos -> length $ filter (atPoint pos) input) gridIndexes
gridIndexes = grid $ bounds input
inputs :: [((Int, Int), (Int, Int))]
inputs = [
((911, 808), (324, 221)),
((161, 890), (808, 243)),
((174, 59), (174, 760)),
((983, 983), (10, 10)),
((321, 12), (870, 12)),
((66, 936), (941, 61)),
((670, 141), (670, 550)),
((783, 935), (496, 648)),
((973, 651), (635, 989)),
((535, 47), (535, 154)),
((355, 183), (754, 582)),
((172, 111), (892, 111)),
((353, 66), (907, 620)),
((741, 960), (741, 805)),
((113, 895), (946, 895)),
((777, 280), (563, 280)),
((679, 815), (626, 815)),
((651, 848), (651, 673)),
((205, 834), (205, 599)),
((895, 118), (82, 931)),
((685, 303), (93, 895)),
((973, 38), (62, 949)),
((867, 23), (867, 300)),
((784, 947), (784, 47)),
((96, 168), (755, 827)),
((909, 321), (909, 716)),
((59, 881), (692, 881)),
((964, 19), (69, 914)),
((752, 869), (67, 184)),
((974, 877), (138, 41)),
((432, 389), (137, 684)),
((458, 822), (458, 402)),
((818, 852), (308, 342)),
((882, 484), (441, 925)),
((82, 959), (976, 65)),
((117, 487), (117, 429)),
((214, 673), (429, 673)),
((72, 955), (72, 829)),
((587, 109), (587, 368)),
((576, 17), (576, 872)),
((685, 102), (685, 905)),
((563, 394), (716, 394)),
((966, 145), (150, 961)),
((555, 582), (555, 385)),
((453, 31), (453, 207)),
((639, 815), (547, 723)),
((431, 869), (431, 811)),
((646, 938), (599, 938)),
((215, 513), (900, 513)),
((809, 82), (798, 82)),
((768, 344), (244, 868)),
((39, 962), (39, 601)),
((675, 186), (61, 186)),
((861, 967), (28, 967)),
((860, 550), (538, 550)),
((283, 740), (571, 740)),
((72, 297), (72, 645)),
((727, 801), (727, 526)),
((799, 519), (799, 497)),
((915, 24), (174, 765)),
((795, 943), (136, 943)),
((518, 971), (599, 971)),
((594, 676), (594, 461)),
((850, 799), (363, 799)),
((958, 575), (958, 231)),
((752, 576), (398, 576)),
((891, 433), (398, 433)),
((524, 126), (397, 126)),
((10, 890), (796, 104)),
((57, 228), (168, 228)),
((168, 521), (338, 691)),
((230, 83), (777, 83)),
((865, 677), (640, 452)),
((866, 821), (825, 821)),
((17, 143), (17, 596)),
((113, 916), (113, 601)),
((268, 187), (551, 470)),
((794, 167), (220, 167)),
((459, 17), (459, 931)),
((211, 31), (526, 31)),
((680, 57), (756, 57)),
((926, 190), (926, 800)),
((85, 284), (63, 284)),
((44, 988), (44, 701)),
((110, 941), (176, 941)),
((480, 163), (480, 112)),
((574, 538), (574, 371)),
((584, 473), (69, 473)),
((303, 621), (303, 380)),
((762, 652), (762, 89)),
((286, 195), (276, 185)),
((957, 87), (217, 827)),
((561, 858), (561, 437)),
((384, 55), (81, 55)),
((19, 977), (981, 15)),
((454, 747), (938, 263)),
((425, 836), (425, 617)),
((860, 135), (775, 50)),
((633, 131), (633, 651)),
((904, 912), (242, 250)),
((880, 177), (480, 577)),
((470, 162), (964, 656)),
((585, 376), (585, 470)),
((696, 760), (594, 862)),
((534, 225), (534, 717)),
((258, 816), (258, 847)),
((990, 244), (990, 93)),
((463, 462), (463, 533)),
((434, 928), (537, 825)),
((813, 734), (533, 734)),
((498, 673), (395, 673)),
((564, 312), (55, 312)),
((280, 550), (939, 550)),
((591, 247), (396, 52)),
((127, 516), (127, 235)),
((850, 425), (552, 127)),
((894, 428), (894, 598)),
((366, 960), (592, 960)),
((579, 488), (170, 488)),
((775, 92), (775, 586)),
((49, 909), (930, 28)),
((856, 113), (284, 685)),
((263, 175), (120, 175)),
((332, 592), (276, 592)),
((920, 157), (141, 157)),
((349, 776), (316, 776)),
((187, 863), (279, 863)),
((218, 872), (83, 872)),
((465, 430), (410, 430)),
((710, 218), (857, 218)),
((797, 314), (184, 314)),
((387, 327), (49, 665)),
((950, 812), (205, 67)),
((803, 133), (803, 682)),
((125, 972), (545, 552)),
((353, 901), (840, 414)),
((936, 843), (202, 109)),
((11, 904), (856, 59)),
((725, 757), (954, 986)),
((227, 697), (345, 697)),
((187, 520), (187, 441)),
((860, 262), (135, 987)),
((700, 95), (976, 371)),
((86, 946), (869, 163)),
((898, 806), (461, 806)),
((717, 796), (717, 195)),
((882, 127), (835, 127)),
((133, 48), (133, 191)),
((521, 51), (521, 927)),
((384, 806), (957, 233)),
((570, 139), (570, 842)),
((949, 819), (949, 350)),
((592, 230), (283, 230)),
((315, 856), (741, 856)),
((870, 674), (549, 353)),
((857, 306), (857, 889)),
((428, 217), (267, 217)),
((47, 93), (898, 944)),
((636, 238), (665, 238)),
((202, 910), (202, 737)),
((246, 432), (617, 803)),
((985, 24), (48, 961)),
((965, 876), (956, 867)),
((618, 650), (810, 458)),
((292, 356), (575, 356)),
((394, 585), (910, 585)),
((137, 453), (137, 178)),
((509, 737), (509, 665)),
((193, 350), (531, 688)),
((805, 219), (107, 219)),
((975, 506), (907, 506)),
((435, 303), (435, 380)),
((344, 83), (344, 224)),
((47, 66), (47, 115)),
((570, 516), (857, 516)),
((162, 91), (926, 91)),
((759, 417), (759, 460)),
((445, 942), (445, 699)),
((421, 340), (421, 743)),
((590, 590), (434, 434)),
((453, 38), (453, 327)),
((865, 134), (865, 773)),
((842, 609), (18, 609)),
((662, 282), (62, 882)),
((489, 32), (344, 32)),
((135, 496), (93, 454)),
((552, 211), (421, 211)),
((620, 678), (642, 678)),
((782, 158), (585, 355)),
((733, 509), (733, 574)),
((932, 383), (369, 946)),
((843, 705), (843, 725)),
((747, 414), (676, 343)),
((294, 218), (962, 886)),
((844, 175), (844, 420)),
((255, 489), (531, 213)),
((555, 532), (821, 532)),
((533, 15), (533, 161)),
((631, 778), (631, 401)),
((75, 282), (468, 282)),
((903, 838), (903, 957)),
((46, 293), (543, 790)),
((30, 834), (30, 948)),
((591, 720), (591, 965)),
((624, 36), (339, 36)),
((425, 323), (425, 442)),
((234, 939), (234, 963)),
((482, 912), (968, 912)),
((228, 614), (189, 614)),
((969, 472), (969, 692)),
((871, 494), (871, 172)),
((101, 624), (848, 624)),
((424, 918), (69, 563)),
((929, 671), (93, 671)),
((81, 187), (707, 813)),
((348, 923), (348, 924)),
((921, 524), (921, 828)),
((678, 454), (678, 364)),
((904, 227), (904, 596)),
((163, 344), (609, 790)),
((206, 180), (206, 59)),
((145, 519), (145, 717)),
((317, 679), (317, 417)),
((503, 724), (221, 724)),
((353, 448), (413, 448)),
((363, 643), (837, 643)),
((594, 54), (359, 54)),
((866, 117), (45, 938)),
((939, 210), (284, 865)),
((410, 556), (410, 801)),
((905, 111), (673, 111)),
((983, 167), (574, 167)),
((595, 758), (97, 758)),
((785, 10), (437, 10)),
((517, 414), (517, 734)),
((691, 567), (186, 62)),
((842, 51), (31, 862)),
((36, 199), (282, 199)),
((864, 758), (864, 610)),
((639, 918), (951, 918)),
((245, 516), (245, 474)),
((951, 203), (557, 203)),
((176, 728), (176, 171)),
((322, 217), (387, 217)),
((149, 208), (836, 895)),
((661, 298), (609, 298)),
((46, 47), (981, 982)),
((769, 45), (769, 610)),
((988, 932), (988, 459)),
((901, 97), (901, 908)),
((195, 395), (121, 395)),
((197, 403), (327, 533)),
((159, 456), (857, 456)),
((480, 981), (881, 580)),
((86, 958), (962, 82)),
((375, 198), (763, 198)),
((950, 381), (341, 381)),
((504, 679), (504, 598)),
((756, 659), (680, 583)),
((146, 328), (886, 328)),
((930, 412), (492, 850)),
((954, 54), (954, 940)),
((790, 498), (790, 305)),
((83, 270), (83, 242)),
((939, 268), (939, 563)),
((423, 756), (916, 263)),
((583, 756), (583, 34)),
((957, 639), (614, 639)),
((484, 523), (521, 560)),
((497, 809), (497, 419)),
((76, 17), (979, 920)),
((49, 39), (943, 933)),
((110, 289), (110, 247)),
((874, 868), (874, 172)),
((576, 127), (53, 650)),
((871, 879), (12, 20)),
((436, 711), (592, 711)),
((132, 285), (225, 285)),
((245, 147), (514, 147)),
((158, 882), (956, 84)),
((21, 984), (937, 68)),
((42, 275), (219, 275)),
((877, 143), (889, 143)),
((593, 841), (508, 756)),
((414, 289), (132, 289)),
((687, 655), (767, 655)),
((453, 981), (459, 987)),
((635, 433), (635, 324)),
((671, 347), (170, 848)),
((412, 579), (915, 579)),
((269, 677), (269, 596)),
((587, 121), (367, 341)),
((153, 883), (153, 709)),
((524, 580), (508, 580)),
((541, 232), (651, 232)),
((93, 948), (284, 757)),
((168, 745), (872, 41)),
((831, 657), (925, 563)),
((908, 389), (442, 389)),
((462, 445), (234, 445)),
((735, 493), (895, 493)),
((274, 624), (296, 646)),
((153, 130), (153, 160)),
((466, 214), (466, 769)),
((474, 499), (686, 711)),
((540, 428), (788, 676)),
((858, 215), (959, 215)),
((788, 91), (788, 410)),
((552, 505), (988, 505)),
((978, 312), (978, 202)),
((108, 321), (616, 829)),
((903, 359), (903, 770)),
((480, 331), (480, 769)),
((503, 842), (34, 842)),
((613, 732), (323, 442)),
((767, 949), (654, 949)),
((514, 589), (386, 589)),
((38, 554), (284, 308)),
((689, 268), (689, 711)),
((860, 66), (190, 736)),
((253, 865), (622, 865)),
((87, 658), (698, 47)),
((506, 892), (829, 569)),
((680, 910), (594, 824)),
((824, 603), (958, 603)),
((576, 802), (562, 802)),
((67, 27), (67, 489)),
((969, 461), (517, 913)),
((674, 763), (674, 226)),
((223, 955), (218, 955)),
((147, 540), (569, 962)),
((455, 703), (596, 703)),
((746, 899), (746, 403)),
((516, 476), (756, 476)),
((897, 674), (373, 150)),
((120, 395), (120, 49)),
((722, 443), (722, 244)),
((724, 924), (724, 39)),
((809, 930), (109, 930)),
((822, 816), (874, 816)),
((796, 539), (895, 539)),
((340, 88), (560, 88)),
((223, 158), (593, 158)),
((779, 977), (856, 900)),
((617, 461), (973, 817)),
((515, 62), (515, 140)),
((12, 586), (724, 586)),
((870, 50), (391, 50)),
((308, 123), (308, 696)),
((119, 164), (863, 908)),
((755, 599), (448, 599)),
((129, 526), (633, 526)),
((478, 668), (102, 668)),
((237, 637), (237, 743)),
((270, 102), (72, 300)),
((115, 470), (115, 427)),
((948, 233), (948, 731)),
((983, 135), (468, 650)),
((748, 439), (748, 642)),
((62, 862), (352, 572)),
((765, 901), (660, 901)),
((917, 807), (917, 587)),
((55, 81), (116, 81)),
((954, 972), (102, 120)),
((340, 503), (294, 549)),
((970, 661), (522, 213)),
((618, 92), (618, 247)),
((688, 965), (965, 965)),
((94, 241), (94, 292)),
((15, 132), (15, 492)),
((979, 927), (488, 927)),
((509, 26), (984, 26)),
((840, 530), (840, 95)),
((55, 956), (849, 162)),
((297, 297), (297, 472)),
((338, 780), (369, 780)),
((487, 292), (37, 292)),
((122, 117), (206, 201)),
((66, 807), (564, 309)),
((643, 242), (906, 242)),
((909, 833), (909, 441)),
((129, 128), (818, 817)),
((406, 42), (406, 297)),
((53, 20), (967, 934)),
((235, 285), (601, 285)),
((275, 625), (275, 539)),
((199, 732), (430, 963)),
((639, 187), (639, 265)),
((549, 740), (549, 824)),
((603, 140), (603, 748)),
((35, 455), (176, 455)),
((888, 611), (888, 271)),
((134, 154), (484, 154)),
((694, 820), (694, 814)),
((535, 584), (187, 932)),
((642, 510), (642, 249)),
((191, 886), (268, 886)),
((918, 353), (881, 390)),
((977, 13), (343, 13)),
((380, 243), (271, 134)),
((410, 758), (410, 670)),
((613, 551), (519, 645)),
((963, 84), (124, 923)),
((702, 252), (821, 252)),
((405, 237), (405, 22)),
((21, 139), (21, 510)),
((548, 499), (132, 499)),
((196, 104), (196, 680)),
((739, 145), (476, 145)),
((751, 746), (91, 746)),
((975, 628), (975, 847)),
((935, 520), (935, 450)),
((803, 372), (803, 393)),
((872, 77), (872, 373)),
((339, 130), (339, 103)),
((226, 886), (226, 45)),
((794, 647), (794, 257)),
((90, 922), (889, 123)),
((615, 971), (615, 574)),
((26, 278), (26, 719)),
((838, 88), (806, 88)),
((263, 691), (804, 150)),
((309, 721), (910, 721)),
((510, 496), (960, 946)),
((195, 236), (46, 236)),
((610, 143), (610, 610)),
((891, 412), (891, 268)),
((714, 21), (156, 579)),
((320, 935), (320, 96)),
((240, 782), (449, 782)),
((754, 472), (48, 472)),
((105, 481), (529, 57)),
((451, 301), (451, 965)),
((796, 638), (796, 185)),
((908, 553), (771, 553)),
((98, 543), (490, 935)),
((481, 159), (762, 159)),
((593, 527), (419, 353)),
((86, 391), (216, 521)),
((260, 716), (42, 716)),
((734, 538), (375, 179)),
((24, 974), (975, 23)),
((402, 466), (787, 851)),
((344, 409), (262, 327)),
((803, 443), (685, 443)),
((986, 152), (249, 152)),
((125, 738), (90, 773)),
((184, 772), (184, 746)),
((729, 829), (729, 340)),
((226, 527), (226, 375)),
((936, 231), (222, 945)),
((254, 333), (254, 167)),
((451, 234), (451, 273)),
((915, 790), (568, 443)),
((869, 794), (504, 429)),
((11, 878), (836, 53)),
((821, 231), (522, 530)),
((285, 419), (732, 866)),
((191, 272), (191, 679)),
((41, 651), (225, 651)),
((30, 13), (879, 862)),
((980, 488), (20, 488)),
((27, 187), (27, 348)),
((53, 238), (53, 514)),
((778, 306), (379, 705)),
((425, 399), (425, 60)),
((162, 859), (57, 859)),
((652, 926), (652, 589)),
((962, 489), (555, 896)),
((197, 378), (436, 617)),
((310, 190), (310, 760)),
((678, 20), (678, 713)),
((390, 653), (985, 58)),
((938, 351), (656, 69)),
((881, 39), (18, 902)),
((313, 681), (323, 681)),
((910, 907), (288, 907)),
((739, 977), (739, 132)),
((856, 479), (154, 479)),
((893, 785), (761, 785)),
((405, 247), (405, 901)),
((58, 933), (808, 183)),
((643, 156), (676, 189)),
((149, 773), (357, 773)),
((479, 518), (434, 518)),
((389, 518), (556, 685)),
((858, 449), (533, 774)),
((503, 133), (409, 133)),
((340, 315), (219, 194)),
((183, 701), (183, 242)),
((810, 151), (195, 151)),
((446, 686), (446, 912)),
((968, 482), (49, 482)),
((203, 20), (203, 667)),
((493, 516), (647, 516)),
((900, 91), (634, 91)),
((660, 554), (119, 13)),
((964, 864), (964, 919)),
((871, 293), (344, 293)),
((895, 258), (972, 258))
]
{-
5167
-}

584
day5part2.swift Normal file
View file

@ -0,0 +1,584 @@
import CoreGraphics
import ImageIO
import Foundation
import UniformTypeIdentifiers
@main
struct Day5Part2 {
let input: [(Point, Point)] = [
((911, 808), (324, 221)),
((161, 890), (808, 243)),
((174, 59), (174, 760)),
((983, 983), (10, 10)),
((321, 12), (870, 12)),
((66, 936), (941, 61)),
((670, 141), (670, 550)),
((783, 935), (496, 648)),
((973, 651), (635, 989)),
((535, 47), (535, 154)),
((355, 183), (754, 582)),
((172, 111), (892, 111)),
((353, 66), (907, 620)),
((741, 960), (741, 805)),
((113, 895), (946, 895)),
((777, 280), (563, 280)),
((679, 815), (626, 815)),
((651, 848), (651, 673)),
((205, 834), (205, 599)),
((895, 118), (82, 931)),
((685, 303), (93, 895)),
((973, 38), (62, 949)),
((867, 23), (867, 300)),
((784, 947), (784, 47)),
((96, 168), (755, 827)),
((909, 321), (909, 716)),
((59, 881), (692, 881)),
((964, 19), (69, 914)),
((752, 869), (67, 184)),
((974, 877), (138, 41)),
((432, 389), (137, 684)),
((458, 822), (458, 402)),
((818, 852), (308, 342)),
((882, 484), (441, 925)),
((82, 959), (976, 65)),
((117, 487), (117, 429)),
((214, 673), (429, 673)),
((72, 955), (72, 829)),
((587, 109), (587, 368)),
((576, 17), (576, 872)),
((685, 102), (685, 905)),
((563, 394), (716, 394)),
((966, 145), (150, 961)),
((555, 582), (555, 385)),
((453, 31), (453, 207)),
((639, 815), (547, 723)),
((431, 869), (431, 811)),
((646, 938), (599, 938)),
((215, 513), (900, 513)),
((809, 82), (798, 82)),
((768, 344), (244, 868)),
((39, 962), (39, 601)),
((675, 186), (61, 186)),
((861, 967), (28, 967)),
((860, 550), (538, 550)),
((283, 740), (571, 740)),
((72, 297), (72, 645)),
((727, 801), (727, 526)),
((799, 519), (799, 497)),
((915, 24), (174, 765)),
((795, 943), (136, 943)),
((518, 971), (599, 971)),
((594, 676), (594, 461)),
((850, 799), (363, 799)),
((958, 575), (958, 231)),
((752, 576), (398, 576)),
((891, 433), (398, 433)),
((524, 126), (397, 126)),
((10, 890), (796, 104)),
((57, 228), (168, 228)),
((168, 521), (338, 691)),
((230, 83), (777, 83)),
((865, 677), (640, 452)),
((866, 821), (825, 821)),
((17, 143), (17, 596)),
((113, 916), (113, 601)),
((268, 187), (551, 470)),
((794, 167), (220, 167)),
((459, 17), (459, 931)),
((211, 31), (526, 31)),
((680, 57), (756, 57)),
((926, 190), (926, 800)),
((85, 284), (63, 284)),
((44, 988), (44, 701)),
((110, 941), (176, 941)),
((480, 163), (480, 112)),
((574, 538), (574, 371)),
((584, 473), (69, 473)),
((303, 621), (303, 380)),
((762, 652), (762, 89)),
((286, 195), (276, 185)),
((957, 87), (217, 827)),
((561, 858), (561, 437)),
((384, 55), (81, 55)),
((19, 977), (981, 15)),
((454, 747), (938, 263)),
((425, 836), (425, 617)),
((860, 135), (775, 50)),
((633, 131), (633, 651)),
((904, 912), (242, 250)),
((880, 177), (480, 577)),
((470, 162), (964, 656)),
((585, 376), (585, 470)),
((696, 760), (594, 862)),
((534, 225), (534, 717)),
((258, 816), (258, 847)),
((990, 244), (990, 93)),
((463, 462), (463, 533)),
((434, 928), (537, 825)),
((813, 734), (533, 734)),
((498, 673), (395, 673)),
((564, 312), (55, 312)),
((280, 550), (939, 550)),
((591, 247), (396, 52)),
((127, 516), (127, 235)),
((850, 425), (552, 127)),
((894, 428), (894, 598)),
((366, 960), (592, 960)),
((579, 488), (170, 488)),
((775, 92), (775, 586)),
((49, 909), (930, 28)),
((856, 113), (284, 685)),
((263, 175), (120, 175)),
((332, 592), (276, 592)),
((920, 157), (141, 157)),
((349, 776), (316, 776)),
((187, 863), (279, 863)),
((218, 872), (83, 872)),
((465, 430), (410, 430)),
((710, 218), (857, 218)),
((797, 314), (184, 314)),
((387, 327), (49, 665)),
((950, 812), (205, 67)),
((803, 133), (803, 682)),
((125, 972), (545, 552)),
((353, 901), (840, 414)),
((936, 843), (202, 109)),
((11, 904), (856, 59)),
((725, 757), (954, 986)),
((227, 697), (345, 697)),
((187, 520), (187, 441)),
((860, 262), (135, 987)),
((700, 95), (976, 371)),
((86, 946), (869, 163)),
((898, 806), (461, 806)),
((717, 796), (717, 195)),
((882, 127), (835, 127)),
((133, 48), (133, 191)),
((521, 51), (521, 927)),
((384, 806), (957, 233)),
((570, 139), (570, 842)),
((949, 819), (949, 350)),
((592, 230), (283, 230)),
((315, 856), (741, 856)),
((870, 674), (549, 353)),
((857, 306), (857, 889)),
((428, 217), (267, 217)),
((47, 93), (898, 944)),
((636, 238), (665, 238)),
((202, 910), (202, 737)),
((246, 432), (617, 803)),
((985, 24), (48, 961)),
((965, 876), (956, 867)),
((618, 650), (810, 458)),
((292, 356), (575, 356)),
((394, 585), (910, 585)),
((137, 453), (137, 178)),
((509, 737), (509, 665)),
((193, 350), (531, 688)),
((805, 219), (107, 219)),
((975, 506), (907, 506)),
((435, 303), (435, 380)),
((344, 83), (344, 224)),
((47, 66), (47, 115)),
((570, 516), (857, 516)),
((162, 91), (926, 91)),
((759, 417), (759, 460)),
((445, 942), (445, 699)),
((421, 340), (421, 743)),
((590, 590), (434, 434)),
((453, 38), (453, 327)),
((865, 134), (865, 773)),
((842, 609), (18, 609)),
((662, 282), (62, 882)),
((489, 32), (344, 32)),
((135, 496), (93, 454)),
((552, 211), (421, 211)),
((620, 678), (642, 678)),
((782, 158), (585, 355)),
((733, 509), (733, 574)),
((932, 383), (369, 946)),
((843, 705), (843, 725)),
((747, 414), (676, 343)),
((294, 218), (962, 886)),
((844, 175), (844, 420)),
((255, 489), (531, 213)),
((555, 532), (821, 532)),
((533, 15), (533, 161)),
((631, 778), (631, 401)),
((75, 282), (468, 282)),
((903, 838), (903, 957)),
((46, 293), (543, 790)),
((30, 834), (30, 948)),
((591, 720), (591, 965)),
((624, 36), (339, 36)),
((425, 323), (425, 442)),
((234, 939), (234, 963)),
((482, 912), (968, 912)),
((228, 614), (189, 614)),
((969, 472), (969, 692)),
((871, 494), (871, 172)),
((101, 624), (848, 624)),
((424, 918), (69, 563)),
((929, 671), (93, 671)),
((81, 187), (707, 813)),
((348, 923), (348, 924)),
((921, 524), (921, 828)),
((678, 454), (678, 364)),
((904, 227), (904, 596)),
((163, 344), (609, 790)),
((206, 180), (206, 59)),
((145, 519), (145, 717)),
((317, 679), (317, 417)),
((503, 724), (221, 724)),
((353, 448), (413, 448)),
((363, 643), (837, 643)),
((594, 54), (359, 54)),
((866, 117), (45, 938)),
((939, 210), (284, 865)),
((410, 556), (410, 801)),
((905, 111), (673, 111)),
((983, 167), (574, 167)),
((595, 758), (97, 758)),
((785, 10), (437, 10)),
((517, 414), (517, 734)),
((691, 567), (186, 62)),
((842, 51), (31, 862)),
((36, 199), (282, 199)),
((864, 758), (864, 610)),
((639, 918), (951, 918)),
((245, 516), (245, 474)),
((951, 203), (557, 203)),
((176, 728), (176, 171)),
((322, 217), (387, 217)),
((149, 208), (836, 895)),
((661, 298), (609, 298)),
((46, 47), (981, 982)),
((769, 45), (769, 610)),
((988, 932), (988, 459)),
((901, 97), (901, 908)),
((195, 395), (121, 395)),
((197, 403), (327, 533)),
((159, 456), (857, 456)),
((480, 981), (881, 580)),
((86, 958), (962, 82)),
((375, 198), (763, 198)),
((950, 381), (341, 381)),
((504, 679), (504, 598)),
((756, 659), (680, 583)),
((146, 328), (886, 328)),
((930, 412), (492, 850)),
((954, 54), (954, 940)),
((790, 498), (790, 305)),
((83, 270), (83, 242)),
((939, 268), (939, 563)),
((423, 756), (916, 263)),
((583, 756), (583, 34)),
((957, 639), (614, 639)),
((484, 523), (521, 560)),
((497, 809), (497, 419)),
((76, 17), (979, 920)),
((49, 39), (943, 933)),
((110, 289), (110, 247)),
((874, 868), (874, 172)),
((576, 127), (53, 650)),
((871, 879), (12, 20)),
((436, 711), (592, 711)),
((132, 285), (225, 285)),
((245, 147), (514, 147)),
((158, 882), (956, 84)),
((21, 984), (937, 68)),
((42, 275), (219, 275)),
((877, 143), (889, 143)),
((593, 841), (508, 756)),
((414, 289), (132, 289)),
((687, 655), (767, 655)),
((453, 981), (459, 987)),
((635, 433), (635, 324)),
((671, 347), (170, 848)),
((412, 579), (915, 579)),
((269, 677), (269, 596)),
((587, 121), (367, 341)),
((153, 883), (153, 709)),
((524, 580), (508, 580)),
((541, 232), (651, 232)),
((93, 948), (284, 757)),
((168, 745), (872, 41)),
((831, 657), (925, 563)),
((908, 389), (442, 389)),
((462, 445), (234, 445)),
((735, 493), (895, 493)),
((274, 624), (296, 646)),
((153, 130), (153, 160)),
((466, 214), (466, 769)),
((474, 499), (686, 711)),
((540, 428), (788, 676)),
((858, 215), (959, 215)),
((788, 91), (788, 410)),
((552, 505), (988, 505)),
((978, 312), (978, 202)),
((108, 321), (616, 829)),
((903, 359), (903, 770)),
((480, 331), (480, 769)),
((503, 842), (34, 842)),
((613, 732), (323, 442)),
((767, 949), (654, 949)),
((514, 589), (386, 589)),
((38, 554), (284, 308)),
((689, 268), (689, 711)),
((860, 66), (190, 736)),
((253, 865), (622, 865)),
((87, 658), (698, 47)),
((506, 892), (829, 569)),
((680, 910), (594, 824)),
((824, 603), (958, 603)),
((576, 802), (562, 802)),
((67, 27), (67, 489)),
((969, 461), (517, 913)),
((674, 763), (674, 226)),
((223, 955), (218, 955)),
((147, 540), (569, 962)),
((455, 703), (596, 703)),
((746, 899), (746, 403)),
((516, 476), (756, 476)),
((897, 674), (373, 150)),
((120, 395), (120, 49)),
((722, 443), (722, 244)),
((724, 924), (724, 39)),
((809, 930), (109, 930)),
((822, 816), (874, 816)),
((796, 539), (895, 539)),
((340, 88), (560, 88)),
((223, 158), (593, 158)),
((779, 977), (856, 900)),
((617, 461), (973, 817)),
((515, 62), (515, 140)),
((12, 586), (724, 586)),
((870, 50), (391, 50)),
((308, 123), (308, 696)),
((119, 164), (863, 908)),
((755, 599), (448, 599)),
((129, 526), (633, 526)),
((478, 668), (102, 668)),
((237, 637), (237, 743)),
((270, 102), (72, 300)),
((115, 470), (115, 427)),
((948, 233), (948, 731)),
((983, 135), (468, 650)),
((748, 439), (748, 642)),
((62, 862), (352, 572)),
((765, 901), (660, 901)),
((917, 807), (917, 587)),
((55, 81), (116, 81)),
((954, 972), (102, 120)),
((340, 503), (294, 549)),
((970, 661), (522, 213)),
((618, 92), (618, 247)),
((688, 965), (965, 965)),
((94, 241), (94, 292)),
((15, 132), (15, 492)),
((979, 927), (488, 927)),
((509, 26), (984, 26)),
((840, 530), (840, 95)),
((55, 956), (849, 162)),
((297, 297), (297, 472)),
((338, 780), (369, 780)),
((487, 292), (37, 292)),
((122, 117), (206, 201)),
((66, 807), (564, 309)),
((643, 242), (906, 242)),
((909, 833), (909, 441)),
((129, 128), (818, 817)),
((406, 42), (406, 297)),
((53, 20), (967, 934)),
((235, 285), (601, 285)),
((275, 625), (275, 539)),
((199, 732), (430, 963)),
((639, 187), (639, 265)),
((549, 740), (549, 824)),
((603, 140), (603, 748)),
((35, 455), (176, 455)),
((888, 611), (888, 271)),
((134, 154), (484, 154)),
((694, 820), (694, 814)),
((535, 584), (187, 932)),
((642, 510), (642, 249)),
((191, 886), (268, 886)),
((918, 353), (881, 390)),
((977, 13), (343, 13)),
((380, 243), (271, 134)),
((410, 758), (410, 670)),
((613, 551), (519, 645)),
((963, 84), (124, 923)),
((702, 252), (821, 252)),
((405, 237), (405, 22)),
((21, 139), (21, 510)),
((548, 499), (132, 499)),
((196, 104), (196, 680)),
((739, 145), (476, 145)),
((751, 746), (91, 746)),
((975, 628), (975, 847)),
((935, 520), (935, 450)),
((803, 372), (803, 393)),
((872, 77), (872, 373)),
((339, 130), (339, 103)),
((226, 886), (226, 45)),
((794, 647), (794, 257)),
((90, 922), (889, 123)),
((615, 971), (615, 574)),
((26, 278), (26, 719)),
((838, 88), (806, 88)),
((263, 691), (804, 150)),
((309, 721), (910, 721)),
((510, 496), (960, 946)),
((195, 236), (46, 236)),
((610, 143), (610, 610)),
((891, 412), (891, 268)),
((714, 21), (156, 579)),
((320, 935), (320, 96)),
((240, 782), (449, 782)),
((754, 472), (48, 472)),
((105, 481), (529, 57)),
((451, 301), (451, 965)),
((796, 638), (796, 185)),
((908, 553), (771, 553)),
((98, 543), (490, 935)),
((481, 159), (762, 159)),
((593, 527), (419, 353)),
((86, 391), (216, 521)),
((260, 716), (42, 716)),
((734, 538), (375, 179)),
((24, 974), (975, 23)),
((402, 466), (787, 851)),
((344, 409), (262, 327)),
((803, 443), (685, 443)),
((986, 152), (249, 152)),
((125, 738), (90, 773)),
((184, 772), (184, 746)),
((729, 829), (729, 340)),
((226, 527), (226, 375)),
((936, 231), (222, 945)),
((254, 333), (254, 167)),
((451, 234), (451, 273)),
((915, 790), (568, 443)),
((869, 794), (504, 429)),
((11, 878), (836, 53)),
((821, 231), (522, 530)),
((285, 419), (732, 866)),
((191, 272), (191, 679)),
((41, 651), (225, 651)),
((30, 13), (879, 862)),
((980, 488), (20, 488)),
((27, 187), (27, 348)),
((53, 238), (53, 514)),
((778, 306), (379, 705)),
((425, 399), (425, 60)),
((162, 859), (57, 859)),
((652, 926), (652, 589)),
((962, 489), (555, 896)),
((197, 378), (436, 617)),
((310, 190), (310, 760)),
((678, 20), (678, 713)),
((390, 653), (985, 58)),
((938, 351), (656, 69)),
((881, 39), (18, 902)),
((313, 681), (323, 681)),
((910, 907), (288, 907)),
((739, 977), (739, 132)),
((856, 479), (154, 479)),
((893, 785), (761, 785)),
((405, 247), (405, 901)),
((58, 933), (808, 183)),
((643, 156), (676, 189)),
((149, 773), (357, 773)),
((479, 518), (434, 518)),
((389, 518), (556, 685)),
((858, 449), (533, 774)),
((503, 133), (409, 133)),
((340, 315), (219, 194)),
((183, 701), (183, 242)),
((810, 151), (195, 151)),
((446, 686), (446, 912)),
((968, 482), (49, 482)),
((203, 20), (203, 667)),
((493, 516), (647, 516)),
((900, 91), (634, 91)),
((660, 554), (119, 13)),
((964, 864), (964, 919)),
((871, 293), (344, 293)),
((895, 258), (972, 258)),
]
func run() {
var minX = 0
var maxX = 0
var minY = 0
var maxY = 0
for line in input {
minX = min(minX, line.0.x, line.1.x)
maxX = max(maxX, line.0.x, line.1.x)
minY = min(minY, line.0.y, line.1.y)
maxY = max(maxY, line.0.y, line.1.y)
}
var grid = Grid(minX: minX, minY: minY, maxX: maxX, maxY: maxY)
for line in input { grid.line(line) }
print(grid.grid.lazy.filter { $0 >= 2 }.count)
let data = CGDataProvider(dataInfo: nil, data: &grid.grid, size: grid.grid.count, releaseData: {_,_,_ in })
let image = CGImage(width: maxX - minX, height: maxY - minY, bitsPerComponent: 8, bitsPerPixel: 8, bytesPerRow: maxX - minX, space: .init(name: CGColorSpace.linearGray)!, bitmapInfo: [], provider: data!, decode: nil, shouldInterpolate: false, intent: .defaultIntent)
let url = URL(fileURLWithPath: "/Users/sven/test.png")
let dest = CGImageDestinationCreateWithURL(url as CFURL, UTType.png.identifier as CFString, 1, nil)
CGImageDestinationAddImage(dest!, image!, nil)
CGImageDestinationFinalize(dest!)
}
struct Grid {
let minX: Int
let minY: Int
let width: Int
var grid: [UInt8]
init(minX: Int, minY: Int, maxX: Int, maxY: Int) {
self.minX = minX
self.minY = minY
width = maxX - minX + 1
let height = maxY - minY + 1
grid = Array(repeating: 0, count: width * height)
}
subscript(x: Int, y:Int) -> UInt8 {
get { grid[(y - minY) * width + x - minX] }
set { grid[(y - minY) * width + x - minX] = newValue }
}
mutating func line(_ line: (Point, Point)) {
let ((minX, minY), (maxX, maxY)) = line
var x = minX
var y = minY
let xStep = minX == maxX ? 0 : minX < maxX ? 1 : -1
let yStep = minY == maxY ? 0 : minY < maxY ? 1 : -1
while true {
self[x, y] += 1
if x == maxX && y == maxY {
break
}
x += xStep
y += yStep
}
}
}
typealias Point = (x: Int, y: Int)
static func main() {
Self().run()
}
}

36
day6.swift Normal file
View file

@ -0,0 +1,36 @@
@main
struct Day6 {
let input = [3,3,2,1,4,1,1,2,3,1,1,2,1,2,1,1,1,1,1,1,4,1,1,5,2,1,1,2,1,1,1,3,5,1,5,5,1,1,1,1,3,1,1,3,2,1,1,1,1,1,1,4,1,1,1,1,1,1,1,4,1,3,3,1,1,3,1,3,1,2,1,3,1,1,4,1,2,4,4,5,1,1,1,1,1,1,4,1,5,1,1,5,1,1,3,3,1,3,2,5,2,4,1,4,1,2,4,5,1,1,5,1,1,1,4,1,1,5,2,1,1,5,1,1,1,5,1,1,1,1,1,3,1,5,3,2,1,1,2,2,1,2,1,1,5,1,1,4,5,1,4,3,1,1,1,1,1,1,5,1,1,1,5,2,1,1,1,5,1,1,1,4,4,2,1,1,1,1,1,1,1,3,1,1,4,4,1,4,1,1,5,3,1,1,1,5,2,2,4,2,1,1,3,1,5,5,1,1,1,4,1,5,1,1,1,4,3,3,3,1,3,1,5,1,4,2,1,1,5,1,1,1,5,5,1,1,2,1,1,1,3,1,1,1,2,3,1,2,2,3,1,3,1,1,4,1,1,2,1,1,1,1,3,5,1,1,2,1,1,1,4,1,1,1,1,1,2,4,1,1,5,3,1,1,1,2,2,2,1,5,1,3,5,3,1,1,4,1,1,4]
var population: [Int] = .init(repeating: 0, count: 9)
func step() -> [Int] {
var result = Array(repeating: 0, count: 9)
for (age, count) in population.enumerated() {
if age == 0 {
result[6] += count
result[8] += count
} else {
result[age - 1] += count
}
}
return result
}
mutating func run() {
for age in input {
population[age] += 1
}
for day in 0..<256 {
population = step()
}
print(population.reduce(0) { $0 + $1 })
}
static func main() {
var x = Self()
x.run()
}
}

267
day8part2.swift Normal file
View file

@ -0,0 +1,267 @@
@main
struct Day8Part2 {
mutating func run() {
var sum = 0
for line in input.split(separator: "\n") {
let parts = line.split(separator: " ")
.filter { $0 != "|" }
.map { Set($0) }
let mapping = self.findMapping(parts[0..<10])
sum += self.decode(parts[10...], with: mapping)
}
print(sum)
}
func findMapping(_ input: ArraySlice<Set<Character>>) -> [String: Int] {
var result: [String: Int] = [:]
var input = input
let one = input.removeFirst { $0.count == 2 }!
let seven = input.removeFirst { $0.count == 3 }!
let four = input.removeFirst { $0.count == 4 }!
let three = input.removeFirst { $0.count == 5 && $0.isSuperset(of: one) }!
let nine = input.removeFirst { $0.count == 6 && $0.isSuperset(of: three) }!
let five = input.removeFirst { $0.count == 5 && $0.subtracting(nine).isEmpty }!
let two = input.removeFirst { $0.count == 5 }!
let zero = input.removeFirst { $0.count == 6 && $0.subtracting(one).count == 4 }!
let six = input.removeFirst { $0.count == 6 }!
result[String(zero.sorted())] = 0
result[String(one.sorted())] = 1
result[String(two.sorted())] = 2
result[String(three.sorted())] = 3
result[String(four.sorted())] = 4
result[String(five.sorted())] = 5
result[String(six.sorted())] = 6
result[String(seven.sorted())] = 7
result["abcdefg"] = 8
result[String(nine.sorted())] = 9
return result
}
func decode(_ input: ArraySlice<Set<Character>>, with mapping: [String: Int]) -> Int {
var result = 0
for digit in input {
result = result * 10 + mapping[String(digit.sorted())]!
}
return result
}
static func main() {
var result = Self()
result.run()
}
let input = """
fgcae ebafc cabdef eg abecfg abgfed feg gafdc bceg ebgcadf | defagbc faecg cfdag gecb
eagd cad fgadbc aefdcg dcebfg fcegd cbeaf ad dbgfeca defca | cfdeg gdcabf fcgde afgced
gfdeca aeb eb fbdag eafdc adfbe cefdab bdaegcf efbc ecadgb | eb dbafe eab faecd
facbdge efdg gcafd daegc caegb aecfdb ade ed gafbdc dgfeac | de abcdef faedcg dfgca
dcaegbf bc dcgeab cbgad cebg cdfaeb fbadg acdge cefdga cdb | gdcfae gbec gdace cgadfe
ceagfbd fbaeg fadge fbegad abgecf dafcg ed edab ged dfcbeg | gebfa de gbafec ed
acedbf adfbg cgafedb geac cgb befcgd bcgaf bfgace cg bfeac | bcdfeg fecba cafgeb bgdfa
egadc cea ac agbcedf cgab bgcade fbcaed eadfbg fegdc ebdag | fdecabg fcged cdbage efgdab
cbfge gdc cdea efdag dc cdfeg gfbcad gcdeaf cdeagbf egfadb | dfcge egcfd fcdbag dc
gaedb fbced gcdbef cge gc decgb dcbgfea cgfb cgdfea fbcade | fdegbac fecbd ecg degba
geaf bcfedg agbcd bfeagd dgfbe cbdaef beacdfg abe agebd ea | fbecdg geaf gebfad adgbc
bed afgebd adecf bafgedc dbca cfegb becdf fabdce bd gcfdea | gfdaeb ebfgad dbefc cbda
gacfebd ag bedfca agbfde egfcab dfga degab fbade bag bdecg | dgaf abcfed agb bfecag
afebg afdeg gcbe acebdf cfbage cafeb gab decgabf bg gcfdba | gb caebf abgef acfebd
efdab fabdgce gcbfa eg gacbfe beg ecag beafg dfabcg bgecfd | bge fgdcbe gcfdba ebdaf
aecbd bdagef gd bfega aefgcbd gfde gfdcab dbg edgba febagc | dg dagfbc dgfe eabdgf
gdfba egfacbd gdcefa baf gcba fdagcb dgfac ab dcfeba ebgdf | dcfag bfa gafcd cbag
afbe bdagc cedfb defcab ebfdgac gfedbc cbfad af adgcfe adf | dafbc dfbac fdcegb gadcb
fcgedb ca fdcage cagdbef ceab acedfb fdbce cafdb cda afgbd | ac dcafb efgdac ebcfda
fbad gbcda dcefgb cfeadg dgbcaf bcafdeg ad gcabe adc dfbcg | gbcdef bcfdg cgbfd bfadgc
afcgeb bedag bdecafg agb bedfga fdagce bg bgfd dfgea cdabe | badge cagdfe efdag afegbd
gfed dcaef ge bafdce daceg acebfg cefadg egc ecdabfg gacdb | bcgad bcegaf agecd degcafb
deacb adcge ab acb fbdce faedbgc fgadec gabd deabgc ecbfag | dfbec ab cbagfe bcfgae
gcabfde ecf cbdeg bacgf fedg ecfgb gfedcb fcaedb cebdag fe | dbcegf bcgdfe gfde defg
daefb bfg gedafb fabge dbafec cfega bdga cgbdfe gb gbacedf | aecfg bcedaf begdcf dgba
bagce bf bdacfeg efbg fcb cefab gbfadc cafebg ecdfa bacdge | fegb cegba bagce efbg
becag cfeg cefgbad fbace gfeacb acdegb bef ef adbcf fdabge | ef bdfac cbegad gbeac
egb afcbe fbaeg eabgfdc gcab gb gfdea fgbecd bcdafe gafbec | fcdgeb edcgbfa gbe fgeba
dga caebd ecdag cegfd abdfce dafbge ecbgda bcdgefa ga agbc | afdbec ecfdab gdaec gad
fc gbdefc cfe ebdaf fcbeda gbafde edacg bfcdgae dacef cabf | decgfba cdbefg cf ecdabf
febgd dafgbc caed cgd ceadgf fbecga dcgfe aegfc gbedfca cd | dgfeb fgced dcafebg agdfce
ecdafgb bgade bgd fabd gbaef bd egadbf ceadg cfbgea dgbfec | edagc bdage bfda dbgae
cgeba aefgcd dfceagb dc ced facbed cdfb dbaec adfeb fgedba | fbdea bgcae efbda fcdeag
caegbf dcfga afcedgb afgdcb fcedag ab edbcg dbfa gdcab abg | bag cbdag agb ab
gadfecb befc fgdbea cf fedagc fac bcgfa agbfe adgcb feagcb | gbcda cgbad bcgfa cf
dae aefcb dgabec dacfg afebdc ebfd afecgb aedcf fbcagde ed | ecabfgd bedf bcadef egdacfb
abcf fcega fdgce fegbda eafdcgb ac gabecd gbfae beagfc eca | edbgca edbfga cae gface
bgedcf afcdbg ag gcbaef fcedgab afgdb cfgbd befda acdg agf | fdbga ceadbfg egfbac fag
bad edafc bdeg abcgde ecafgbd gfadcb bgaec db edcba geafcb | cdafe fdcabg cdfageb dbge
geb bgcf agfcde gb befag gfbcae defab gabdec eacfg gabecfd | afbedgc gceabf abgef egacf
fdeac acg cfegda cbeadf fegdbca ag acefg adge bfdgca gbcfe | gecdaf efgca cgbafd cfgeb
begdf bdfgc ebcf adfcg cdegbf dgeafb cbg cb bfeagdc gbdcea | acgedb fagdbe bgfde dfgac
afcgdb aedc bedgf egafcd afdge gecaf fcgebda gda da ceabfg | gedbf gacfe adg agdef
bdeafg acgebdf dgcfa fa cafe dgfbc gaf edagfc cgabde agedc | fadbge bdgfcea dgcefa cgeda
gacfbde defag cbgef gbca efadcb afcbeg cgbdfe ba eba gefab | fegab abe ebfcgd fbgae
gfbdec fbcade cabdegf ebdg bfd dcfgb cadgf gebcf db fcabge | eacdgfb bdge ebdg ecafdb
egcfba fdcae fcdaeb gcfdae fabd ba cdeab fcdbaeg eba decbg | cabed facbed cbade dfcea
agdfe acfdeg fcdbeg dgf gdaec df cadf ceagbfd abgfe gbdaec | bgcdef abfge gbefcd df
dgebf afgdb bfa fcbade af dcafgb agcf gcbda dabgecf gadecb | dbcga abcdge fadgbce eagcbd
dbcga bea egacdf dageb be efbd abgfce gadfe fcbegad aebfdg | eba be bdage bedga
gcbd egbdafc fgc fbgedc gc aedbfg cefgb fedbg cfaegd efabc | bface egfbc bgdacfe gc
fdgae dc ced gbcd gbcefd decfba becfg ecfabg cgfde gbcadfe | edbcfg cd cafgbe cdegbf
geadcf efg gadef fg fecad acbgfe dagecbf dcgf gadbe afbdce | edafcg bgcfade gfdc abedg
edcba ecgdb aedbcf aebf dabfc fdacge badgfc ae ead gfcbade | gcebdaf degbc ebfadc efdcba
caedbg dbgec dcbf ecgdbf cgdef dgf bgaedcf egacf afebgd fd | cdfbeg ecfbgda gcbfed cbgedf
bdag acdeb ecgdb egbcfa fcdbega gb dbecag cbdafe ebg gdcef | bedgc abdfcge efagcb cdgef
bfade bfdga dfbgec cagbfd dfgacbe gba gacf ag gdcbf abgedc | cfag abdcge ebafd abefd
agcdef bcfda bdgca aebdfcg eagdc gb dbg gbea cedagb bfgdec | dfabgec eafdgc acdge gdecab
ebacdfg cgbfad egdbc bdgfa daef bae gabed febadg ae gacbef | fagdb daebgf fgdab bea
dcgbf cbedf degc bgc fcgdbea fbadg cfdgbe gc efacgb fdbace | edfcb cfeabg cg edbacf
bcdagfe dfacb cbfdge bgcdf fdgeac acd agbd acbef da dcgfba | cbgdf dgab ad gbdcaf
edgfbca gbe be ceba bdaecg gefcd dbagc egbadf dcegb dfgabc | gcfde gfceabd gfbcad eagfdb
dfcbg fcdga efgb gecbfd gecbda dfbgaec bedfc dgb bfadce bg | dbcgf bfge dacgf dfgcbe
cga ebdgaf bfdag cbgfe bfadgc gbfeadc ac cagfb cdba cgadef | bfdag agedcf aegcbfd gcfab
gcead gfdbec cbdge gabfce eb dfgcba ecfdgab befd dgcbf ebg | cdgae fbdegc bcdge gcdfb
da ebgfda fcdeagb acgbfe gedba dbegc agdecf dae bafeg bfda | gdafec fegba edfbga aed
fbagec gdfba bcg gebcfd cbafg bcdfgea ebac cefag faedcg bc | gfbac baegcfd fabegc dgeacbf
dfbeag fabdg fdbe abdeg eb dcega gcefba cfdbag dgcfbae geb | cgbafd bdef dcage eb
abdcfe gba dagf cagbefd fdbea bfega ag dafbge dcbeag gfceb | afbcde ecgfb dfbega bdgeca
dg dge gdbc cfdae bcgae cbdage abgfde cfedagb cdgae eacgbf | eabgc bgeac bcdg cagbe
bfd dgaeb gcabde fd bfgce dgfa dbefg gadbfce dbafge fabcde | edfcba efbcg df bdf
gcbfd agbecd fedc edcbfg fdb eadfbg bcfag fd gedcb gbacdef | fgbac bdagfec gfbdaec aegbdc
cgbdfe ce acedg adcfeg bcfegad fcea ceg abdeg afbdcg fcgda | ecg aefdcg dacge ec
egbdfca efacb agcdbe cbaed bdafgc dfaecg debg bd bda agced | geadbc efbca gabfdc bd
edcfb bfgecd ecabfd eca abcd fgeab fedcag abfedgc ac bfeca | bgfae eca cdgfeb bfaec
cadef cebdga ebd bacdfe dagfec dbfa fcebg ecbgfad db fdecb | befcd acgdeb abdf dbfa
gbfecda bfd cdagb fbdacg fgdbec gbaf cbadf aefdc eadcgb bf | adcgb dfbca agbf dafcb
abedg acbgf fd gaefcb cagbdef cdaf dcbfeg bdagf dgcbfa bfd | gbadcef df fadgb gabcdf
fbgadc dbcfg dcega cgdfe cfedbg caefgb ef gef gfaebcd fedb | fcedg febd gbcdfa cdgfab
bg adgb fcaedbg cgfda fcbae bcg dfacge fgcdba decgfb bcagf | cgafb dbfcage bdgcfe dbga
ed afbdg acefb aecbfg cfdabeg gedfcb fcdabe ecda def ebdfa | gbafd gedfcb dfegcb dfgba
gcdfae efgdb abdfcg fde gdabf dbcegfa fedgab efab ef ebdcg | eafb gbfda gacedf cbdge
edagfc gfaecbd bgced cbegfd cb gefdc badgfc bdc efbc adegb | dgbec cegafd dcbgef dgecb
gedcab beg eg cafgb fbegc gdfe bdgfec gabcedf bdafce bcdfe | gcefb afcbed ge gdfe
fdbagc cdgefab edacf ceba ea cfbaed ecfdg abfegd adfbc eda | ea beadfc abcgdef ecdgf
fbc gfbacd fecda cbdfa dbgf dceabg gbcdfea efbgac cdabg bf | gbdf agbced gaedbc gfdb
aegcb bfgecd fbegad fcagdbe dfgce fcbd gdeacf fb bgf bgfce | bgafedc gcdaef dgfcbe eadgcf
def dbce agdfeb ed fdgbcea dgcfb aegfc dfgbac gecfd cdfgbe | cdfegb ed cdgfaeb ebdc
ecbfad afdb eagbfc caebgdf edfcb dgfec cgdbae bd bcafe bdc | bfacegd fbdcae dbc bgfdcea
dfgba eg cfbead gde bfedgc dceab cabfdge gdbae aecg aedgcb | egd adebg gde debcfa
cadfb egfb afgbc adbegc ecgadf ecagb fga ecfgab bgacfde fg | afcbg cgfba gf dacbge
cegbf dec efcdg facdge dfae dcbafge ed adgfc fdbagc cgaebd | dce gbcfe afcdgbe dcgabf
cfabe fa eabgfc cgaf fba gfbce dcfbge edbgcfa efbadg acebd | cfebga bfa fedcagb abfce
acdfb dbagf afcebgd beag afgedb gfdea gbd fgdcbe gb cdeagf | dafge gafed gfacde gb
gdfeac dfgce ebfadcg edagc dacf baegdc fd gdf egcfb dabgef | degfbac cfdeg daebgf cdeagb
fcgabe ebcd ecfdg dabcgf gfecabd cfd ebcfg dc bcfegd adefg | agedf cd bcefg dc
cbaeg bcfea fb feb gfaceb gdfbec dagbec gfab deacf bgcaedf | acbfge bf afgb efb
egdba cadgfbe efadbg cg begc bfgdca caegd abcegd dcg acdfe | fbegcad bceg gcd cdgebaf
agbcd dafcgb cfdg ceadb fdgeba eafbcg gfdab gbc bgdcafe cg | gfadcbe fbagd decba gc
gfbec adgc dge egdcfa abgfde abgdfce dg eacfdb fdaec gdfce | fecgd gd fgcbe acdef
fdbceg bfedc af fegcad cbdag daf efab dabcef fbeadgc cbfad | fcabd cbfad gcfdbe gadbc
ebgac fabdeg bedca cg aegdcfb geacbf ceg efgba facg fbedcg | gecdfb aebfg fagc ceg
eagb dcgeb ba abd cbeagd cdgafb fecbdga fgedcb dacfe dacbe | bdfeacg cadgbf bgedfc fcdae
dbac cfgae cbfgde ba bga gcfbad dcfebga gcdbf feagbd cgbaf | cgafb fagbdc dcfbg afgebd
adbgfe fgb egdafc cbafd dfegbc edgafbc egfcd cegb gfcdb gb | bg fdacge efcadg egdfba
agfbe cgaefdb gbdf edagb afg cdgafe gfedab fg egcdba fabec | fcbdega fag agf agf
cae edabfc cdfega ca cfba gadeb fdecb ecagfbd cbgdef acdeb | facdeb fgecad bfadce efcgbad
facb dbfec dceabf efgcd cb aecfbgd dgfbae eafdb ebdagc bcd | bfedc cdegab cbdfe adefb
fecbga badgc dga bfgadec dg geacb cgedba dfebag gcde fcabd | decg gda baceg gd
gecbd gcbdfea cbfg bg bge egbcdf dcbef beafdc cdeag bfgeda | agcde dceag gfabde beg
gefba gacfbe facdeg cg cgab gfc efbdcag cfgeb cefbd afegbd | gfc afbge dafegb aebcgf
egd aebfgd gefc ge gedbfca bdcfe dfcegb gecdb edbacf cdbag | dacbg edcfbg bcdfe ge
df ebdga gcdefa cfbd bgdfa afgcb dfeagbc bfacgd fgd facebg | gaebd gecbaf fdcb dfbag
fag cegfdab cadebg dabcgf abefg eafc ecafgb ebacg fbdge fa | ebfag dbcgfae gbecad fdbgac
gecbd gefa gfc fabdcg bfaecd ecgafbd fg befgc efabc gecbfa | gfae gcf egbdafc edgbc
bfgae fcebag fdbe fd fedag adgfbc fdbgea ecagd agcbfed fad | fgabe dfeb ebfd gefba
ecdgfb afge bdage ebcda eg abdgef fgadb gabcfd dge bcdagef | gdebfa eg agfbdec afeg
dbc acefd cegadbf fbcde afcb fdcaeg bc acdbge febdac debfg | ceafd caefd gfbaced dcb
fecgb fgacd gdcefba de gbafce febd gecfd edc fecdbg ecbgda | becdfg ed becgad gcdeba
agfdbe fbac bcd edacfb bgecfd cb cdeba cfgdeab acged edfab | cb dbc adbce bdfae
dgacef bdfa ecgbf ab fegba dgafe efdbgca abg acebdg afbdge | gefda ecgafd ecfbg begcad
gbfcea bgfa afdebc aegdcb af bgcdfea bgeac gecdf afc fgace | bfgecad fca afc abfg
cfe dgcfe fdagcb gebdc egfa gbcdefa dcebfa fe agdfc fgaedc | dfgac fe fce fcdbega
fecgab gcbdef cbaefgd dfgbe dgcfe eb bfe dbfga edbc acfegd | fbdeg fdgeca agefbc egcfd
aecd bac dfacbe cafdb ac gefcab gfcdbe fcbde gbdaf cbdegaf | gcdbefa fbgcae ecad fagecb
eagbf cagedf geafdbc fdgbce adefb aecfd adcb deb faecbd bd | ebd deabf fadcge cdagfe
gadefcb bfcga eadcgb egdbfc deag ecg edabc acedbf eg abgce | gdea bagce gce gce
agcfe bec gecab gbeda facb dbfgec fcegab gfacde gfdaceb cb | cb cefdgb cadefgb bc
fdgb df egabcf fegda cedga fegab efdbac def cgdefba gafedb | facdbe bafceg agedf fdebga
fdaecg dbcafg abfgec dc caefg cedg aecfd abdgfce eadbf fcd | cgefab gbfacd fbegac fabecg
dfecabg bcfeag gdafce dagbfc cdefb dca gafbc dbag da bcadf | dca bagfce cbfda cdagbf
dabfgec febadg gbcdae gfbe adebf ef cabdf edfgca ebgda eaf | gfacbed abgced egdfca egfb
cfdea dc fdagebc fegcbd agdc gcfade fcabe cfd efdgba gfead | bdfcge agdc dgefa cfd
gbfca febadcg bc bdegcf beca begaf gabedf cgfbae cgfad cbg | bcg dcaefgb dfgceb afebdg
cg cgbf bedcg fcagde adefbcg efdgcb ebacd cgd edbfg egdafb | cfgedb bgcf acegdf cfgb
bfad adcgbe faceg fagbdc df afdgc efcbdag dfbegc gfd badcg | gfd abgcd fgd abfd
bcadgf cgdfb adgcb gf gafc dcfeabg bdagce dgf dfbega cebdf | adcbfg gfca fdcbe gfac
daebf fcabgde bgdcef gab ga edbcga afcg ebfga aefbgc egbcf | ebcfg ebcgfa fcgebd agcf
gedab fg afgecb cfgd feg cfabed befdc fgdcbe gdceafb befgd | ecafbg ecfbd febdc gf
gcbadf ce gfcdb fec feabd gbecdf dbcfage febdc agcdfe egbc | bafed gcbe gefcbd egcb
cbdfg gbcafd feb gaecf gcbfe gfbdae be fcgabde bdgcef becd | abgedf gdfebc aedgfb fbe
edacgbf fbdae edgac bg gab bagdec dagfce fadbgc cebg bgdea | aedgb bg cebg adcge
bda gbfea gedcab gfbceda bgdfa bfcdg febcdg bagcfd cfad da | dbecag bgfdc gdbfa facd
ceabd dabfe acgde bc fbca cgbfde febgda dfecagb ebafdc bdc | cbdae dbfea fgdceb gbfedc
acg fadbgce cfgdeb dbgce efdca ag dbga cagbef egacd cdgbea | gdecabf gcbfea ecbdg gac
dfgacb ged egfdab efcgbda gcefbd debga ebadc ge aegf gfdab | cdfgab cdafgb bfcgda ge
gdbeca bcfde eafg cefbgad dgafcb ge degfb adefbg dgfba bge | bdfeg begdf ebfadg eabdfgc
cfbdgae gbaec bagfcd gfcba dcaeg bacfeg dbeacf bec efgb eb | ceb egcab cagfb dgcae
fdcagb gdaecb fcadg bcdgaef gd dfcea gbcaf aecgfb cgd dgbf | gfadc gfdb badgfc gbfca
bcafed defgcab fgcb cfbae cagde agebfc gbcae gbe gadefb gb | bg gfcaeb bg aedgc
bcfadeg gbfd eacfbd gdafe afebg bafegd geafcd gebca fb bfa | agdefc eafbdg fgead gedaf
fcgeabd dgeaf ebgfad gceafb geadc ac aec ebcdg cafd adgefc | gbfadec egcbd acfd dgabef
eac fbdgec ea eadb cbaeg agfdecb eafdgc dcgbe bcfga adcbeg | aec abde eac ea
cedb gcadbe ed edgfbac fbega abdge gacdb fdacgb dcefag aed | cdagb gbcafd gdefac gedafc
cae agfbec ae begcd feab fadgbc ecfadg ecabg cdgbefa cabfg | ecgba afcgb efba dgeafc
fecgabd badf efadg abedfg fea fdgceb fedgb aebfgc af gdcae | ebfgca fae fea af
bgedac gbfae dcbefg acbf fb gaedf cagedbf aebgc gebfca fgb | aedgf fdgea bgfae bfdgeac
bagcfe eadcb gb facegdb bgc fdcag efbcad beadgc bgadc ebgd | gbc fbcage becad gbfcae
cagde gbca dcgbea gc efcad dbgfea dfgecb caedbfg adgbe cdg | gc egdfbc bcga cg
efgcbd aebgcd dfe eadfb abged abdcefg bacfd ef bdfaeg faeg | fgae cgdaeb adefb afcbd
cgbfea gcbda gefdcb eadf febag bdf fd febgad fadbegc bgadf | gebcfd fgdbea dfb dbf
dg cdgfe gecfad dfbce bgefda fgd eafcg efcbag dgac bcdagfe | afdebg gfd aecgf gfcea
edfga cgefda gcdbe fbae ab egdabf cfgbda deabg bad adefcgb | ebadg agdeb fbae gbdae
gbdcfa gbade ebgac ecbfa adfgbec badecf bgc gcef fbgace gc | gc fcge gacefdb ebgca
acefgd ebgaf egfda egcd bgfaecd dgcfa ed abcefd efd abdgcf | def ebgaf fed befcda
fecag cag cfagbd agfcbde fabec eabg fdcge cgbfea fadebc ag | cfgbda dfgbeca efdcg dfgcaeb
bgecfda ecdag dgfcbe bdgac adbgf afgdbe bfac gdcabf cbd bc | bc acbgefd fagcdb fcba
ba efacg cfbgde cfdbg bacgf bgfdea abf bcad cfbeadg bgcfad | bcdgef fdgaeb ab cagfe
cbdaf bafdgc eacbd fd dcf fcabg bcdfeg bedgcfa dgfa agbecf | dfga bgfac df agdf
edcabf cadbf bgfdcea bgcfad bgcde dfg fg bdfgc cgadfe abfg | adfecg gfbcd acgdfeb cbgdaf
badgfc dg bagcde bceda dbcfea beafg debag adg fcbadeg edgc | gebda dcagbf dceba egfab
edcf dacfbg dbcefag fbd df bdegfc ebdagc bgfea begcd bfedg | dgebc cbgde dgfbac bdf
bdcfg acegfb acebfd fdcag egadcf da daf cgeaf edag bafcegd | gdcaf fgaec bafdec fdaecb
cagefd fde gdfba fcgaedb abefd ef dafbeg ebfg afcbgd ebdca | egdbfa bceda dfabg bdace
fcgb gcdae bg gfadeb cbfegd fcabed bdg gcdbe fdcbe adbefcg | dgb gfbdec befdc gfbc
fabde bgfde bgecda cedgb gf cabfdeg ebfdgc fgbeac fcdg gfb | fgbde efdgb edgbc afedb
ebacf cedfab fde eabfd fd baecgf bagde agdebfc dfcb egfadc | ebfdgac acdegf abdefc ebfad
gdcb cd cfgae cgbedf fbegd efgdc fadcbe gfeacdb dce dfagbe | gbcd cde gacfe gefdbc
geb afedgb bfegca bgade eg dgef gadbc eafdb afebdcg fcbead | cagbd defcba dbafec geafcb
fgbdc gbfade gba gefa dbafg cbadge bfgecda ga edbafc dfabe | afbdeg dgfba bgdfa dcfgb
agef badce ef febad cabfdg gdfab cbgeafd egfbdc defgba fbe | abefd geaf gafdbe ebcad
gd gad bfdg gecba fedabcg fcgeda aedfbc adebf agbdfe dgeab | ebcdaf agd gcfbdae egacb
cedbfa ba cgbfa abf dfegac cafeg gabe befgca ebdfcag cbfdg | fab aegcf faecbd fdcebga
daefg febdga aegfdbc efgdca eafb bge eb agbdec febgd gbdfc | gbcfd edbfg egb bacegd
fbdecg bdafec cfaeb gedac def dceaf abfd fd gfecba gfdaecb | ebfac bdfa gbcdef fd
fcbga cbdfeag bafgce fdacg dc fcd fcgbad fadge efcdgb cdab | gaefcb bafegcd acdb abcgf
ecgabd acgdf abge ae bcfead fgdaceb ead daegc bcdefg gcbed | egba gaecd cgadbe gdbce
aegfbc gf afebdc agebdfc ebcdf feg dcefg bdfg dcgea bgedcf | edbfcg fdgb bdgafce febgcd
dcg bcdefa dbfceg fdeacg acbeg bfeagcd cfdae dg dfag agdec | dfcgea dg egdca edagc
agcfeb fagbed fdbceg bag gebfd afgd agbfcde acbed ag badeg | cbdea fcedgb gfebac abcegf
adbegfc fgdace cadge afcg ebdfca ebgad eac bfgdce cgefd ca | acged fcedg ebagd dgacefb
gfeadb gfeab bcfa agebcfd aebgfc fecgbd efc fc gadec egcfa | fgbace fc debgcf afgceb
bacg ab cfgbd bfadge acfed fgdecb agedcbf fcabgd bfa dbafc | gfdcb cbga abcg afecbdg
ge beagc cfgabd bgaced bgcda fbadgec age ecdagf egbd fcbae | aeg gedbac cadfeg fbgcda
dgbafe abfdgec gdf fd agebcf gadec dfcgba befd edfga aebfg | abcgefd dagec dfg df
edfcga bcegd baeg cbgdae agdbc gce acgdebf eg gfadbc cefbd | dcbeg bgedc cedbg edcbg
adfbe dg cagef dfgb gdbeca aefdg gda edcbaf fdgeba gdecbfa | cdabef eafbd bafcegd dg
cd edcbfg dbage fcaebdg facd bgcfea afbedc afbec dbc adecb | adegb bcefag abegd cbgedf
gdcbf da ecgbfda adc adgb bagcfd dfbcea egfac dfbceg gdacf | gdba cfdbg adbfec fcaeg
bcg bc gdcbae dbca abfgde gdeba ebfacdg egcba faceg dgfbce | geadb badecg ecbfgd baecg
"""
}

186
day9.swift Normal file
View file

@ -0,0 +1,186 @@
@main
struct Day9: Puzzle {
let matrix = Self.input.compactMap { $0.wholeNumberValue }
let width = 100
let height = 100
subscript(x: Int, y: Int) -> Int {
get {
return matrix[x + width * y]
}
}
func isMinimum(x: Int, y: Int) -> Bool {
let value = self[x, y]
let smallerLeft = x == 0 || self[x - 1, y] > value
let smallerRight = x == width - 1 || self[x + 1, y] > value
let smallerTop = y == 0 || self[x, y - 1] > value
let smallerBottom = y == height - 1 || self[x, y + 1] > value
return smallerLeft && smallerRight && smallerTop && smallerBottom
}
func run() {
var lowPoints: [(Int, Int)] = []
var riskSum = 0
for y in 0..<height {
for x in 0..<width {
if isMinimum(x: x, y: y) {
riskSum += self[x,y] + 1
lowPoints.append((x,y))
}
}
}
print("Part 1:", riskSum)
let basins = lowPoints.map { basinSize(x: $0.0, y: $0.1) }
.sorted(by: { $0 > $1 })
.prefix(3)
.reduce(1, *)
print("Part 2:", basins)
}
func basinSize(x: Int, y: Int) -> Int {
basinAt(Point(x: x, y: y)).count
}
subscript(point: Point) -> Int {
self[point.x, point.y]
}
func basinAt(_ p: Point) -> Set<Point> {
var set: Set<Point> = []
findBasin(at: p, value: self[p] - 1, visited: &set)
return set
}
func findBasin(at point: Point, value: Int, visited: inout Set<Point>) {
guard !visited.contains(point) else { return }
guard point.x >= 0 && point.y >= 0 && point.x < width && point.y < height else { return }
let currentValue = self[point]
guard currentValue != 9 && currentValue > value else { return }
visited.insert(point)
findBasin(at: point.left, value: currentValue, visited: &visited)
findBasin(at: point.up, value: currentValue, visited: &visited)
findBasin(at: point.right, value: currentValue, visited: &visited)
findBasin(at: point.down, value: currentValue, visited: &visited)
}
struct Point: Hashable {
var x: Int
var y: Int
var left: Point { .init(x: x - 1, y: y) }
var right: Point { .init(x: x + 1, y: y) }
var up: Point { .init(x: x, y: y - 1) }
var down: Point { .init(x: x, y: y + 1) }
}
static let input = """
5796798621237995498765434567987542999765679987545679109878999877899789876532123456998999876887899921
4645976434456789349654321298997679898654698987635678998767897656789698765432012347897899865676798799
3234987545978993298795410989998989789543256897646789498756789546896579877842123456976789954345985678
4356798679989999019987329878999798679765345689856991296545890134789467998956899967895698643239874579
6467999789999898934976598967987676568996457999967999987636789345691346789769987898934987651098763456
7598997999987796899989987959876543456789569898998998765125678956910298899898776799123998862987652345
8789876789865685578999876645987665567998689656789876554034899999891989998987564679099789879876543456
9898765498974324456799865534598786788998798645889985432126954987789878987654323567988698989987664678
9989997987543212367987654323459897899549895434569876556437899876599967996543212459876587898998798789
9877989997662101456798765434567998967932987624778989787548999989679459987687301349875456967899899893
8765678998983232367899896765788939346891295434999999899659879699894349899796532656954344756910923964
9874789019894343456789949878999321235799987545678945998778964578942139769898543769843212345891949765
7965678998765764567893433989876542346987898656789236799889653989943298652999678989754523456789898976
6598789109976975698921012398999763457896559867997647989998799899874569541098799798765676579896687897
5439898929989989789962123457899894568989435998998799878999989798765798432149898649987787899965456989
5212987898999999899854336568999989879979326569109989567898879689878987544234995434599898999874345679
4309875987999876998765687679989878998765412458929875467987854599989698955679989323459979899993214589
5996954676799984329877788989878969899874324567899765359876743489996549877789878912398767789984323456
9875432545789743212989899998967659789985595678998868249965312679865435998898767899598954698765467567
2994321036897654101996936987654543679999989789997854198764301569979423459999954678997643789978578978
0987432128998763219875424698763212478998978999876543298773212458998901267898767889598732345988789989
9876544346789979329876512349998401569897569234987994987654343457897892478999878993349891234899998695
9989875679899898939984701459886212398786456946799889998795464567896789989896999321234989345678987544
9997987889998797998743212598765323987654397899989778999989978679945698999765678930349878956999898433
8986798999987676789655329679876439876541289998878656899867898791239956799954345959499867897899765321
7845679219878565678976598999987556998732378997667545798656789892398745999765237898987656789998654310
6434798998765454567897987898798677899543467896553234987545878989499636878992156987975345899219964324
0123987999874343456789876799549789987654598998421056989434767879976521767989249876543234998909878434
4339876798955102367898985678939891099967899876542159875323854568965410156978956997684456797899989545
5498765986543234488987894799012999129878999987653249986210123467894321249769767898795867956789199656
6599754397654545589996789899993998949999998799767998975351237998995432398758998989986788946999098789
7988732198765657678975698999879876898946999544979877989876456789987643459647899876097899534878999899
9876546019878767889984567899968765667939896532989966592987887893298754598756789965198997323456799989
0998757898989899992099789988754543457898789540199854301298998984129866789998999954249986412345899878
1299898987699954954299999876543212348987698921598763212349999873234977995679439765356897601234988767
2989999876569999895989986987654103467896567892349854334568989964345698934678921976897996532349875756
9879899988698988789878995498976215989995456789498999965689879899456789323567890197998987656756994345
8765677899987677697667896329865423499989997995987878897798768778968895438678991298969398967899873201
8654546789766563459548994219876534578977789104986567789949654567899976657899789349543219988932965412
8643437899854312998435689101987645689665679323975345678959868778957987798934679959654301299549876723
6532126778969409876424578912498756796553568939863203456899979989646799899012567898976432358956987894
8544434567998912998535689843569867989432459949954212568999989594535798989123467987976563567969799985
9655566789897893479697897654567979879421267898767343467898795443123497679935679876899674789997659876
9776789998656799567989998765678998967992349929876556578987654321012989567896798765678985999876642989
9988899875434678979878999879889987657889458919997967689798865452199867456987987654567896798765431096
8799943989545789999868799989999876545678967898789898797659979874987654347899999753459987979876532145
7679969998656789987657678994323965432789979987679789896535989995998321234568939894567899764987687236
7567898959767893976543467995909876645678989996545678965423599989899754359679421986789968973199875345
3467987644978912987784989879899987856789999987434569653213679876789866468789439898993459792012989466
6569999533989999798896797867789898987897999876424678962102398765898977578996598769322375679933496578
8678998921296789679987896545698769399986789764312398993923499654567897689398999954201234567894987689
9799867890145679542998987896789954234995698765101256789894987543458999791249899895312347899995798789
2988656891237789869879998998996895999876789864212345996789987652377899910299756789436556799989999890
3977545789347899998767899989434999879989898987423467895678993210466789321987645679987867989767899921
9865437896556789999946799876545998767999987976534789954589997621245679459876437898798979876545978943
9976545789697899987834689989699767656899876989675678932679876432556789598943218997659989765434567894
9989867899989999986545678995987654545998965498797889321996997543457898797654323789943596986546789965
8896978999879878997668789213986543234987894349898996549875698665678909998965534567892345697656798987
7645989898765655689779898901987662129876789234989998698954539987899919879877645689931257898767967899
9869998789964334578995937892397654398945689345678979987643012398967898767998776798890234999898957898
6998789679892123457894325943498765987834568956889467898952134579656899656549887897789656799999546457
5987654597651012349975434799579989865423567897992378999763245678947999743435998996549767987989432347
4398753299843123457896545678992099654512455789209989398754356789439879842124999987638989876678954456
1239854987653238768998956999989298743101234678998994298765768899598765431029892196547898965466795567
0123995799768545678969869878979349543213455789997899109976779998789987532139789987656987654345789979
3235986999879656789756999867668956975434696899986987912987899999894697643298678999987898543234567898
9945799876998798897645987654456899876595989989765976899998999886989987659987567998998999864365788977
8799895995439899986534598732367968988989878979954695678919998785468998798766456997899898765479899766
5678923994323999876545987543478957999976556767893254589101987674378789899854349876799649876678987645
4567919876214899987689998954989546898765432356789123678919986543245679998765467965678999987789298756
3467898765436789998998999879995434999896521237895019789998997532135998899977569876789988798992109867
2369929876545699999987899999876545689943210235994298999997989949239876789989778989899976569993298989
3458910997676789899876989212987676899656432346789987889886979898949965679999899998998665478989987897
4567899998787895798765678923598789998789545497899996779765765787898764567878921987999543289567976546
6878978999898934989894569654589890249899876569999884568954654656989843458967899876998992123458997997
7989569899919129878989678979678931239964998978998763477943212349879932123458998765876789012567919989
8991356779909019767678989989899842498643239989987542356799302345965431014568919954345692139898929879
9410124567898998654567891294998753679654134699876521245678913459876432323589109765457789256799598767
4321267898987549876899910123987654598763245698776410234569865567997943434578999988767899767895349654
6532356789876434987898943235698765679854659987654321345678976778999894565689989999878949878943298765
7656467893987545998967896545699887998767998998765432456889988999998789689789878989999432989752129976
8767589954899756899459987756989998919879897899876548668994599989987678999898769878997643496543234988
9879678975798967987598999899878959102998766999988767899123678978986567894987653967898765789759449999
2989789996987898998987899954969643213459945789799878943239989865454478923986542656949896899898998931
1299899989776999129976899769878965425678996999656989965398798754342349435965421248956997899987687899
0467999876545789098865689879989876566789987898768997897987659983210456949878543367899898999876546797
2378988965434678987674778998999998987893598999879876798965434975672569898987665456789789998695435896
4499877994323569876523467897988999999912459999989965689896323497883479767999787578995679876564326345
9987656789212489986313568966767897899106598989999984878789212598965998956799898989664868975432101234
8798878994323478965423459954456986798919987678999873165678943679879876545689939996543459876875212345
9659989765434568976796567893299765987898765569898762054567894578998765434696549987654667998994323476
8934599879876899997898879954987654496987654346789943123489965679539854323589998998767898989889456567
7895678998987899998999998769876543345798765767898894344567896789329875434567897689998999878778967678
6796989987698969799998789878998632134899878998946799465679987898919987645679976578999098767669898799
5789995799549347689987678999986721023999999769434878987989998967898998767989787459989298653456789910
4567894698432134567988566789875432335698798653212967999997859456987679878998643212578987832345679891
3779992976553235679977455698998765487987689864343458999876543237897569989797652101459876543456789789
9889689987664346798765323456789887569876598765454569986987652145789698795698768892368987956567895678
4994567899865457999974313345699998798765439879875678955698767234999987654229878765456799767878934589
2123456999876567899875101256789109999984321989989899543249878945678996542101989877667899878989123699
"""
}