Day 23 - Part 1

This commit is contained in:
Sven Weidauer 2020-12-24 07:58:28 +01:00
parent dc25ae1ea7
commit 395c30a952
2 changed files with 139 additions and 0 deletions

View file

@ -35,6 +35,9 @@
26DD9CF52591C4000082D4F2 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DD9CF42591C4000082D4F2 /* main.swift */; }; 26DD9CF52591C4000082D4F2 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DD9CF42591C4000082D4F2 /* main.swift */; };
26DD9D0F2591C40C0082D4F2 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2ACE5257ED09000702405 /* Extensions.swift */; }; 26DD9D0F2591C40C0082D4F2 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2ACE5257ED09000702405 /* Extensions.swift */; };
26DD9D102591C40C0082D4F2 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2AD3A2581713A00702405 /* LoadData.swift */; }; 26DD9D102591C40C0082D4F2 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2AD3A2581713A00702405 /* LoadData.swift */; };
26DD9D2E259312410082D4F2 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26DD9D2D259312410082D4F2 /* main.swift */; };
26DD9D49259312460082D4F2 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2ACE5257ED09000702405 /* Extensions.swift */; };
26DD9D4A259312460082D4F2 /* LoadData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2AD3A2581713A00702405 /* LoadData.swift */; };
26E2ACD8257ECFFA00702405 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2ACD7257ECFFA00702405 /* main.swift */; }; 26E2ACD8257ECFFA00702405 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2ACD7257ECFFA00702405 /* main.swift */; };
26E2ACE6257ED09000702405 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2ACE5257ED09000702405 /* Extensions.swift */; }; 26E2ACE6257ED09000702405 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2ACE5257ED09000702405 /* Extensions.swift */; };
26E2ACE7257ED09000702405 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2ACE5257ED09000702405 /* Extensions.swift */; }; 26E2ACE7257ED09000702405 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26E2ACE5257ED09000702405 /* Extensions.swift */; };
@ -202,6 +205,15 @@
); );
runOnlyForDeploymentPostprocessing = 1; runOnlyForDeploymentPostprocessing = 1;
}; };
26DD9D29259312410082D4F2 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
26E2ACD3257ECFFA00702405 /* CopyFiles */ = { 26E2ACD3257ECFFA00702405 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase; isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
@ -305,6 +317,8 @@
26DD9CA82590759B0082D4F2 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; }; 26DD9CA82590759B0082D4F2 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
26DD9CF22591C4000082D4F2 /* day22 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = day22; sourceTree = BUILT_PRODUCTS_DIR; }; 26DD9CF22591C4000082D4F2 /* day22 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = day22; sourceTree = BUILT_PRODUCTS_DIR; };
26DD9CF42591C4000082D4F2 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; }; 26DD9CF42591C4000082D4F2 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
26DD9D2B259312410082D4F2 /* day23 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = day23; sourceTree = BUILT_PRODUCTS_DIR; };
26DD9D2D259312410082D4F2 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
26E2ACD5257ECFFA00702405 /* day8 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = day8; sourceTree = BUILT_PRODUCTS_DIR; }; 26E2ACD5257ECFFA00702405 /* day8 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = day8; sourceTree = BUILT_PRODUCTS_DIR; };
26E2ACD7257ECFFA00702405 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; }; 26E2ACD7257ECFFA00702405 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
26E2ACE5257ED09000702405 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; }; 26E2ACE5257ED09000702405 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
@ -424,6 +438,13 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
26DD9D28259312410082D4F2 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
26E2ACD2257ECFFA00702405 /* Frameworks */ = { 26E2ACD2257ECFFA00702405 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
@ -525,6 +546,7 @@
26DD9C72258F2CEE0082D4F2 /* day20 */, 26DD9C72258F2CEE0082D4F2 /* day20 */,
26DD9CA72590759B0082D4F2 /* day21 */, 26DD9CA72590759B0082D4F2 /* day21 */,
26DD9CF32591C4000082D4F2 /* day22 */, 26DD9CF32591C4000082D4F2 /* day22 */,
26DD9D2C259312410082D4F2 /* day23 */,
268D953A25781DD80030EC4D /* Products */, 268D953A25781DD80030EC4D /* Products */,
); );
sourceTree = "<group>"; sourceTree = "<group>";
@ -554,6 +576,7 @@
26DD9C71258F2CEE0082D4F2 /* day20 */, 26DD9C71258F2CEE0082D4F2 /* day20 */,
26DD9CA62590759B0082D4F2 /* day21 */, 26DD9CA62590759B0082D4F2 /* day21 */,
26DD9CF22591C4000082D4F2 /* day22 */, 26DD9CF22591C4000082D4F2 /* day22 */,
26DD9D2B259312410082D4F2 /* day23 */,
); );
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
@ -654,6 +677,14 @@
path = day22; path = day22;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
26DD9D2C259312410082D4F2 /* day23 */ = {
isa = PBXGroup;
children = (
26DD9D2D259312410082D4F2 /* main.swift */,
);
path = day23;
sourceTree = "<group>";
};
26E2ACD6257ECFFA00702405 /* day8 */ = { 26E2ACD6257ECFFA00702405 /* day8 */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -968,6 +999,23 @@
productReference = 26DD9CF22591C4000082D4F2 /* day22 */; productReference = 26DD9CF22591C4000082D4F2 /* day22 */;
productType = "com.apple.product-type.tool"; productType = "com.apple.product-type.tool";
}; };
26DD9D2A259312410082D4F2 /* day23 */ = {
isa = PBXNativeTarget;
buildConfigurationList = 26DD9D31259312410082D4F2 /* Build configuration list for PBXNativeTarget "day23" */;
buildPhases = (
26DD9D27259312410082D4F2 /* Sources */,
26DD9D28259312410082D4F2 /* Frameworks */,
26DD9D29259312410082D4F2 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = day23;
productName = day23;
productReference = 26DD9D2B259312410082D4F2 /* day23 */;
productType = "com.apple.product-type.tool";
};
26E2ACD4257ECFFA00702405 /* day8 */ = { 26E2ACD4257ECFFA00702405 /* day8 */ = {
isa = PBXNativeTarget; isa = PBXNativeTarget;
buildConfigurationList = 26E2ACDB257ECFFA00702405 /* Build configuration list for PBXNativeTarget "day8" */; buildConfigurationList = 26E2ACDB257ECFFA00702405 /* Build configuration list for PBXNativeTarget "day8" */;
@ -1155,6 +1203,9 @@
26DD9CF12591C4000082D4F2 = { 26DD9CF12591C4000082D4F2 = {
CreatedOnToolsVersion = 12.3; CreatedOnToolsVersion = 12.3;
}; };
26DD9D2A259312410082D4F2 = {
CreatedOnToolsVersion = 12.3;
};
26E2ACD4257ECFFA00702405 = { 26E2ACD4257ECFFA00702405 = {
CreatedOnToolsVersion = 12.2; CreatedOnToolsVersion = 12.2;
}; };
@ -1216,6 +1267,7 @@
26DD9C70258F2CEE0082D4F2 /* day20 */, 26DD9C70258F2CEE0082D4F2 /* day20 */,
26DD9CA52590759B0082D4F2 /* day21 */, 26DD9CA52590759B0082D4F2 /* day21 */,
26DD9CF12591C4000082D4F2 /* day22 */, 26DD9CF12591C4000082D4F2 /* day22 */,
26DD9D2A259312410082D4F2 /* day23 */,
); );
}; };
/* End PBXProject section */ /* End PBXProject section */
@ -1361,6 +1413,16 @@
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
26DD9D27259312410082D4F2 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
26DD9D2E259312410082D4F2 /* main.swift in Sources */,
26DD9D49259312460082D4F2 /* Extensions.swift in Sources */,
26DD9D4A259312460082D4F2 /* LoadData.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
26E2ACD1257ECFFA00702405 /* Sources */ = { 26E2ACD1257ECFFA00702405 /* Sources */ = {
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
@ -1885,6 +1947,28 @@
}; };
name = Release; name = Release;
}; };
26DD9D2F259312410082D4F2 /* 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;
};
26DD9D30259312410082D4F2 /* 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;
};
26E2ACD9257ECFFA00702405 /* Debug */ = { 26E2ACD9257ECFFA00702405 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
@ -2215,6 +2299,15 @@
defaultConfigurationIsVisible = 0; defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
26DD9D31259312410082D4F2 /* Build configuration list for PBXNativeTarget "day23" */ = {
isa = XCConfigurationList;
buildConfigurations = (
26DD9D2F259312410082D4F2 /* Debug */,
26DD9D30259312410082D4F2 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
26E2ACDB257ECFFA00702405 /* Build configuration list for PBXNativeTarget "day8" */ = { 26E2ACDB257ECFFA00702405 /* Build configuration list for PBXNativeTarget "day8" */ = {
isa = XCConfigurationList; isa = XCConfigurationList;
buildConfigurations = ( buildConfigurations = (

46
day23/main.swift Normal file
View file

@ -0,0 +1,46 @@
var stack = [9, 5, 2, 3, 1, 6, 4, 8, 7]
extension Array {
mutating func rotateLeft(mid: Index) {
let slice = self[0..<mid]
removeSubrange(0..<mid)
append(contentsOf: slice)
}
}
func round() {
let picked = stack[1 ... 3]
stack.removeSubrange(1 ... 3)
var destination = stack[0]
repeat {
destination -= 1
if destination < 1 {
destination = 9
}
} while picked.contains(destination)
let destinationIndex = stack.firstIndex(of: destination)! + 1
stack.insert(contentsOf: picked, at: destinationIndex)
stack.rotateLeft(mid: 1)
}
func printStack() {
for (offset, value) in stack.enumerated() {
print(offset == 0 ? "(\(value))" : "\(value)", terminator: " ")
}
print()
}
for i in 0..<100 {
print("\(i + 1)) ", terminator: "")
printStack()
round()
}
print("Final: ", terminator: "")
printStack()
let oneIndex = stack.firstIndex(of: 1)!
stack.rotateLeft(mid: (oneIndex + 1) % stack.count)
print(stack.dropLast().map {"\($0)"}.joined())