Move to subdirectory
This commit is contained in:
parent
c4ae807a5f
commit
c7deb3c71d
47 changed files with 1208 additions and 0 deletions
2588
2020/AdventOfCode2020.xcodeproj/project.pbxproj
Normal file
2588
2020/AdventOfCode2020.xcodeproj/project.pbxproj
Normal file
File diff suppressed because it is too large
Load diff
7
2020/AdventOfCode2020.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
7
2020/AdventOfCode2020.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
Binary file not shown.
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26DD9C70258F2CEE0082D4F2"
|
||||
BuildableName = "day20"
|
||||
BlueprintName = "day20"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Release"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26DD9C70258F2CEE0082D4F2"
|
||||
BuildableName = "day20"
|
||||
BlueprintName = "day20"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26DD9C70258F2CEE0082D4F2"
|
||||
BuildableName = "day20"
|
||||
BlueprintName = "day20"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26DD9D2A259312410082D4F2"
|
||||
BuildableName = "day23"
|
||||
BlueprintName = "day23"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Release"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26DD9D2A259312410082D4F2"
|
||||
BuildableName = "day23"
|
||||
BlueprintName = "day23"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26DD9D2A259312410082D4F2"
|
||||
BuildableName = "day23"
|
||||
BlueprintName = "day23"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
uuid = "36021C9A-4464-4ABE-A9A0-5882AA0A15A8"
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
<Breakpoints>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "B6DE3A23-1DEA-41C0-9A3C-380FEB7662CD"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "day4/main.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "18"
|
||||
endingLineNumber = "18"
|
||||
landmarkName = "passport()"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "36293FE6-6B6E-4947-87BA-0772B519DE2C"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "day7/main.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "42"
|
||||
endingLineNumber = "42"
|
||||
landmarkName = "scanAllRules()"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "2CA49F47-E4A5-4034-8A42-6B6293ADCF82"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "day7/main.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "23"
|
||||
endingLineNumber = "23"
|
||||
landmarkName = "scanRuleSet()"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "B712C82A-7138-421A-850F-FB27DBEF0976"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "day7/main.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "15"
|
||||
endingLineNumber = "15"
|
||||
landmarkName = "scanRule()"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D953825781DD80030EC4D"
|
||||
BuildableName = "day1"
|
||||
BlueprintName = "day1"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D953825781DD80030EC4D"
|
||||
BuildableName = "day1"
|
||||
BlueprintName = "day1"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D953825781DD80030EC4D"
|
||||
BuildableName = "day1"
|
||||
BlueprintName = "day1"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,85 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2AD1D25816EE100702405"
|
||||
BuildableName = "day10"
|
||||
BlueprintName = "day10"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2AD1D25816EE100702405"
|
||||
BuildableName = "day10"
|
||||
BlueprintName = "day10"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<EnvironmentVariables>
|
||||
<EnvironmentVariable
|
||||
key = "SESSION"
|
||||
value = "53616c7465645f5f1e046b7ba943afdff478d694fdcf9740892842deb001d83a9fff2916886de26a1258e59b30190085"
|
||||
isEnabled = "YES">
|
||||
</EnvironmentVariable>
|
||||
</EnvironmentVariables>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2AD1D25816EE100702405"
|
||||
BuildableName = "day10"
|
||||
BlueprintName = "day10"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,85 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2AD52258343D800702405"
|
||||
BuildableName = "day11"
|
||||
BlueprintName = "day11"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2AD52258343D800702405"
|
||||
BuildableName = "day11"
|
||||
BlueprintName = "day11"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<EnvironmentVariables>
|
||||
<EnvironmentVariable
|
||||
key = "SESSION"
|
||||
value = "53616c7465645f5f1e046b7ba943afdff478d694fdcf9740892842deb001d83a9fff2916886de26a1258e59b30190085"
|
||||
isEnabled = "YES">
|
||||
</EnvironmentVariable>
|
||||
</EnvironmentVariables>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2AD52258343D800702405"
|
||||
BuildableName = "day11"
|
||||
BlueprintName = "day11"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,85 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2AD802584A61F00702405"
|
||||
BuildableName = "day12"
|
||||
BlueprintName = "day12"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2AD802584A61F00702405"
|
||||
BuildableName = "day12"
|
||||
BlueprintName = "day12"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<EnvironmentVariables>
|
||||
<EnvironmentVariable
|
||||
key = "SESSION"
|
||||
value = "53616c7465645f5f1e046b7ba943afdff478d694fdcf9740892842deb001d83a9fff2916886de26a1258e59b30190085"
|
||||
isEnabled = "YES">
|
||||
</EnvironmentVariable>
|
||||
</EnvironmentVariables>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2AD802584A61F00702405"
|
||||
BuildableName = "day12"
|
||||
BlueprintName = "day12"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D954725781F740030EC4D"
|
||||
BuildableName = "day2"
|
||||
BlueprintName = "day2"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D954725781F740030EC4D"
|
||||
BuildableName = "day2"
|
||||
BlueprintName = "day2"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D954725781F740030EC4D"
|
||||
BuildableName = "day2"
|
||||
BlueprintName = "day2"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9558257904250030EC4D"
|
||||
BuildableName = "day3"
|
||||
BlueprintName = "day3"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9558257904250030EC4D"
|
||||
BuildableName = "day3"
|
||||
BlueprintName = "day3"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9558257904250030EC4D"
|
||||
BuildableName = "day3"
|
||||
BlueprintName = "day3"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9566257A07B80030EC4D"
|
||||
BuildableName = "day4"
|
||||
BlueprintName = "day4"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9566257A07B80030EC4D"
|
||||
BuildableName = "day4"
|
||||
BlueprintName = "day4"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9566257A07B80030EC4D"
|
||||
BuildableName = "day4"
|
||||
BlueprintName = "day4"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9575257B52290030EC4D"
|
||||
BuildableName = "day5"
|
||||
BlueprintName = "day5"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9575257B52290030EC4D"
|
||||
BuildableName = "day5"
|
||||
BlueprintName = "day5"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9575257B52290030EC4D"
|
||||
BuildableName = "day5"
|
||||
BlueprintName = "day5"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9585257CB8DA0030EC4D"
|
||||
BuildableName = "day6"
|
||||
BlueprintName = "day6"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9585257CB8DA0030EC4D"
|
||||
BuildableName = "day6"
|
||||
BlueprintName = "day6"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "268D9585257CB8DA0030EC4D"
|
||||
BuildableName = "day6"
|
||||
BlueprintName = "day6"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2617623E257DFD0800D00A66"
|
||||
BuildableName = "day7"
|
||||
BlueprintName = "day7"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2617623E257DFD0800D00A66"
|
||||
BuildableName = "day7"
|
||||
BlueprintName = "day7"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2617623E257DFD0800D00A66"
|
||||
BuildableName = "day7"
|
||||
BlueprintName = "day7"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2ACD4257ECFFA00702405"
|
||||
BuildableName = "day8"
|
||||
BlueprintName = "day8"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2ACD4257ECFFA00702405"
|
||||
BuildableName = "day8"
|
||||
BlueprintName = "day8"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2ACD4257ECFFA00702405"
|
||||
BuildableName = "day8"
|
||||
BlueprintName = "day8"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,85 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1300"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2ACF9258009FE00702405"
|
||||
BuildableName = "day9"
|
||||
BlueprintName = "day9"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2ACF9258009FE00702405"
|
||||
BuildableName = "day9"
|
||||
BlueprintName = "day9"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<EnvironmentVariables>
|
||||
<EnvironmentVariable
|
||||
key = "SESSION"
|
||||
value = "53616c7465645f5f1e046b7ba943afdff478d694fdcf9740892842deb001d83a9fff2916886de26a1258e59b30190085"
|
||||
isEnabled = "YES">
|
||||
</EnvironmentVariable>
|
||||
</EnvironmentVariables>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "26E2ACF9258009FE00702405"
|
||||
BuildableName = "day9"
|
||||
BlueprintName = "day9"
|
||||
ReferencedContainer = "container:AdventOfCode2020.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,172 @@
|
|||
<?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>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>day1.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>10</integer>
|
||||
</dict>
|
||||
<key>day10.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>2</integer>
|
||||
</dict>
|
||||
<key>day11.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>3</integer>
|
||||
</dict>
|
||||
<key>day12.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>12</integer>
|
||||
</dict>
|
||||
<key>day13.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>12</integer>
|
||||
</dict>
|
||||
<key>day14.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>15</integer>
|
||||
</dict>
|
||||
<key>day15.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>19</integer>
|
||||
</dict>
|
||||
<key>day16.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>23</integer>
|
||||
</dict>
|
||||
<key>day17.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>20</integer>
|
||||
</dict>
|
||||
<key>day18.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>21</integer>
|
||||
</dict>
|
||||
<key>day19.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>24</integer>
|
||||
</dict>
|
||||
<key>day2.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>6</integer>
|
||||
</dict>
|
||||
<key>day20.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>13</integer>
|
||||
</dict>
|
||||
<key>day21.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>27</integer>
|
||||
</dict>
|
||||
<key>day22.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>25</integer>
|
||||
</dict>
|
||||
<key>day23.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>14</integer>
|
||||
</dict>
|
||||
<key>day24.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>17</integer>
|
||||
</dict>
|
||||
<key>day25.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>29</integer>
|
||||
</dict>
|
||||
<key>day3.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>7</integer>
|
||||
</dict>
|
||||
<key>day4.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>9</integer>
|
||||
</dict>
|
||||
<key>day5.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>11</integer>
|
||||
</dict>
|
||||
<key>day6.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>8</integer>
|
||||
</dict>
|
||||
<key>day7.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>5</integer>
|
||||
</dict>
|
||||
<key>day8.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>4</integer>
|
||||
</dict>
|
||||
<key>day9.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
<dict>
|
||||
<key>26DD9C70258F2CEE0082D4F2</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>26DD9D2A259312410082D4F2</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>26E2ACF9258009FE00702405</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>26E2AD1D25816EE100702405</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>26E2AD52258343D800702405</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>26E2AD802584A61F00702405</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>26E2ADA82586024700702405</key>
|
||||
<dict>
|
||||
<key>primary</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
38
2020/common/Extensions.swift
Normal file
38
2020/common/Extensions.swift
Normal file
|
@ -0,0 +1,38 @@
|
|||
import Foundation
|
||||
|
||||
extension Scanner {
|
||||
@discardableResult
|
||||
func string(_ string: String) -> Bool {
|
||||
return scanString(string) != nil
|
||||
}
|
||||
|
||||
func integers() -> [Int] {
|
||||
var numbers: [Int] = []
|
||||
while let num = scanInt() {
|
||||
numbers.append(num)
|
||||
}
|
||||
return numbers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension String {
|
||||
func lines() -> [String] {
|
||||
var result: [String] = []
|
||||
enumerateLines { line, _ in result.append(line) }
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
extension Sequence {
|
||||
func print(_ prefix: String = "") -> Self {
|
||||
Swift.print(prefix, Array(self))
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
extension Collection where Element: Collection {
|
||||
func flatten() -> [Element.Element] {
|
||||
flatMap { $0 }
|
||||
}
|
||||
}
|
28
2020/common/LoadData.swift
Normal file
28
2020/common/LoadData.swift
Normal file
|
@ -0,0 +1,28 @@
|
|||
import Foundation
|
||||
|
||||
func loadData(day: Int) -> String {
|
||||
let session = (try! String(contentsOf: FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".config/aoc2020session"))).trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
var request = URLRequest(url: URL(string: "https://adventofcode.com/2020/day/\(day)/input")!)
|
||||
request.setValue("session=\(session)", forHTTPHeaderField: "Cookie")
|
||||
|
||||
var result: String? = nil
|
||||
|
||||
let group = DispatchGroup()
|
||||
|
||||
group.enter()
|
||||
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
|
||||
guard error == nil, let data = data, let response = response as? HTTPURLResponse, response.statusCode == 200 else {
|
||||
fatalError("Cannot get input from server")
|
||||
}
|
||||
|
||||
result = String(data: data, encoding: .utf8)
|
||||
group.leave()
|
||||
}
|
||||
|
||||
task.resume()
|
||||
|
||||
group.wait()
|
||||
|
||||
return result!
|
||||
}
|
21
2020/day1/main.swift
Normal file
21
2020/day1/main.swift
Normal file
|
@ -0,0 +1,21 @@
|
|||
import Foundation
|
||||
|
||||
let input = Scanner(string: loadData(day: 1)).integers()
|
||||
|
||||
for i in 0..<input.count {
|
||||
for j in i..<input.count {
|
||||
for k in j..<input.count {
|
||||
let a = input[i]
|
||||
let b = input[j]
|
||||
let c = input[k]
|
||||
|
||||
if k == j && a + b == 2020 {
|
||||
print("1st", a * b)
|
||||
}
|
||||
|
||||
if a + b + c == 2020 {
|
||||
print("2nd", a * b * c)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
64
2020/day10/main.swift
Normal file
64
2020/day10/main.swift
Normal file
|
@ -0,0 +1,64 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 10)
|
||||
let scanner = Scanner(string: input)
|
||||
|
||||
var adapters = scanner.integers().sorted { $0 > $1 }
|
||||
adapters.append(0)
|
||||
|
||||
|
||||
let device = adapters[0] + 3
|
||||
|
||||
var current = device
|
||||
var ones = 0
|
||||
var threes = 0
|
||||
|
||||
for adapter in adapters {
|
||||
let step = current - adapter
|
||||
if step == 3 {
|
||||
threes += 1
|
||||
} else if step == 1 {
|
||||
ones += 1
|
||||
} else if step != 2 {
|
||||
print("fail")
|
||||
}
|
||||
current = adapter
|
||||
}
|
||||
|
||||
print("part 1", ones * threes)
|
||||
|
||||
struct Key: Hashable {
|
||||
var start: Int
|
||||
var max: Int
|
||||
}
|
||||
var memo: [Key: Int] = [:]
|
||||
|
||||
func findPaths(start: Int, max: Int) -> Int {
|
||||
if let value = memo[Key(start: start, max: max)] {
|
||||
return value
|
||||
}
|
||||
|
||||
let diff = max - adapters[start]
|
||||
if diff > 3 || diff < 1 {
|
||||
return 0
|
||||
}
|
||||
|
||||
if start == adapters.count - 1 {
|
||||
return 1
|
||||
}
|
||||
|
||||
var result = 0
|
||||
for n in (start + 1)..<(adapters.count) {
|
||||
let next = findPaths(start: n, max: adapters[start])
|
||||
if next == 0 {
|
||||
break
|
||||
}
|
||||
result += next
|
||||
}
|
||||
|
||||
memo[Key(start: start, max: max)] = result
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
print(findPaths(start: 0, max: device))
|
116
2020/day11/main.swift
Normal file
116
2020/day11/main.swift
Normal file
|
@ -0,0 +1,116 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 11)
|
||||
|
||||
enum Spot: Equatable {
|
||||
case empty
|
||||
case occupied
|
||||
case floor
|
||||
}
|
||||
typealias Map = [[Spot]]
|
||||
|
||||
var map: Map = []
|
||||
|
||||
input.enumerateLines { (line, _) in
|
||||
map.append(line.map {
|
||||
switch $0 {
|
||||
case ".": return .floor
|
||||
case "#": return .occupied
|
||||
case "L": return .empty
|
||||
default: fatalError("Invalid input")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
let adjacents = [
|
||||
(-1, -1),
|
||||
(0, -1),
|
||||
(1, -1),
|
||||
(-1, 0),
|
||||
(1, 0),
|
||||
(-1, 1),
|
||||
(0, 1),
|
||||
(1, 1)
|
||||
]
|
||||
|
||||
/*
|
||||
func step(map: Map) -> Map {
|
||||
var result = map
|
||||
let width = map[0].count
|
||||
|
||||
for i in 0..<map.count {
|
||||
for j in 0..<width where map[i][j] != .floor {
|
||||
let occupieds = adjacents.reduce(0) { count, offset in
|
||||
let (x, y) = (offset.0 + j, offset.1 + i)
|
||||
guard 0..<map.count ~= y, 0..<width ~= x else { return count }
|
||||
return count + (map[y][x] == .occupied ? 1 : 0)
|
||||
}
|
||||
switch (map[i][j], occupieds) {
|
||||
case (.empty, 0): result[i][j] = .occupied
|
||||
case (.occupied, let n) where n >= 4: result[i][j] = .empty
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
func occupiedInDirection(at pos: (Int, Int), map: Map, direction: (Int, Int)) -> Int {
|
||||
var pos = pos
|
||||
|
||||
let yRange = 0..<map.count
|
||||
let xRange = 0..<map[0].count
|
||||
|
||||
while true {
|
||||
var (i, j) = pos
|
||||
i+=direction.1
|
||||
j += direction.0
|
||||
pos = (i, j)
|
||||
|
||||
guard yRange ~= pos.0, xRange ~= pos.1 else { break }
|
||||
|
||||
let state = map[i][j]
|
||||
switch state {
|
||||
case .floor: break
|
||||
case .occupied: return 1
|
||||
case .empty: return 0
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func step(map: Map) -> Map {
|
||||
var result = map
|
||||
let width = map[0].count
|
||||
|
||||
for i in 0..<map.count {
|
||||
for j in 0..<width where map[i][j] != .floor {
|
||||
let occupieds = adjacents.reduce(0) { count, offset in
|
||||
count + occupiedInDirection(at: (i, j), map: map, direction: offset)
|
||||
}
|
||||
switch (map[i][j], occupieds) {
|
||||
case (.empty, 0): result[i][j] = .occupied
|
||||
case (.occupied, let n) where n >= 5: result[i][j] = .empty
|
||||
default: break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
while true {
|
||||
let next = step(map: map)
|
||||
if next == map {
|
||||
break
|
||||
}
|
||||
map = next
|
||||
}
|
||||
|
||||
let totalOccupieds = map.lazy.flatMap { $0 }.filter { $0 == .occupied }.count
|
||||
print(totalOccupieds)
|
65
2020/day12/main.swift
Normal file
65
2020/day12/main.swift
Normal file
|
@ -0,0 +1,65 @@
|
|||
import Foundation
|
||||
let input = loadData(day: 12)
|
||||
|
||||
let scanner = Scanner(string: input)
|
||||
|
||||
var position = (north: 0, east: 0)
|
||||
var waypoint = (north: 1, east: 10)
|
||||
var direction = 0
|
||||
|
||||
/*
|
||||
while !scanner.isAtEnd {
|
||||
guard let instruction = scanner.scanCharacter(), let value = scanner.scanInt() else {
|
||||
fatalError("Invalid input")
|
||||
}
|
||||
|
||||
switch instruction {
|
||||
case "N": position.north += value
|
||||
case "S": position.north -= value
|
||||
case "E": position.east += value
|
||||
case "W": position.east -= value
|
||||
case "L": direction = (360 + direction - value) % 360
|
||||
case "R": direction = (direction + value) % 360
|
||||
case "F":
|
||||
switch direction {
|
||||
case 0: position.east += value
|
||||
case 90: position.north -= value
|
||||
case 180: position.east -= value
|
||||
case 270: position.north += value
|
||||
default: fatalError("Invalid direction")
|
||||
}
|
||||
default: fatalError("Invalid command")
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func turn(_ degrees: Int) -> (north: Int, east: Int) {
|
||||
switch degrees {
|
||||
case 0: return waypoint
|
||||
case 90: return (-waypoint.east, waypoint.north)
|
||||
case 180: return (-waypoint.north, -waypoint.east)
|
||||
case 270: return (waypoint.east, -waypoint.north)
|
||||
default: fatalError("Invalid direction")
|
||||
}
|
||||
}
|
||||
|
||||
while !scanner.isAtEnd {
|
||||
guard let instruction = scanner.scanCharacter(), let value = scanner.scanInt() else {
|
||||
fatalError("Invalid input")
|
||||
}
|
||||
|
||||
switch instruction {
|
||||
case "N": waypoint.north += value
|
||||
case "S": waypoint.north -= value
|
||||
case "E": waypoint.east += value
|
||||
case "W": waypoint.east -= value
|
||||
case "R": waypoint = turn(value)
|
||||
case "L": waypoint = turn(360 - value)
|
||||
case "F":
|
||||
position.north += value * waypoint.north
|
||||
position.east += value * waypoint.east
|
||||
default: fatalError("Invalid command")
|
||||
}
|
||||
}
|
||||
|
||||
print(abs(position.north) + abs(position.east))
|
61
2020/day13/main.swift
Normal file
61
2020/day13/main.swift
Normal file
|
@ -0,0 +1,61 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 13)
|
||||
|
||||
|
||||
let scanner = Scanner(string: input)
|
||||
|
||||
let startTime = scanner.scanInt()!
|
||||
|
||||
var busLines: [(Int, position: Int)] = []
|
||||
|
||||
var position = 0
|
||||
repeat {
|
||||
if let line = scanner.scanInt() {
|
||||
busLines.append((line, position))
|
||||
} else if scanner.string("x") {
|
||||
// Ignore
|
||||
}
|
||||
position += 1
|
||||
} while scanner.string(",")
|
||||
|
||||
let min = busLines
|
||||
.map { $0.0 }
|
||||
.map { ((startTime / $0) * $0 + $0, $0) }
|
||||
.print()
|
||||
.min(by: { $0.0 < $1.0 })!
|
||||
|
||||
|
||||
print((min.0 - startTime) * min.1)
|
||||
|
||||
let max = busLines.max(by: { $0.0 < $1.0 })!
|
||||
print(max)
|
||||
|
||||
/*
|
||||
brute force - takes too long
|
||||
|
||||
var s = sequence(first: 0, next: { $0 + max.0 })
|
||||
.lazy
|
||||
.filter { t in busLines.allSatisfy { (t - max.position + $0.position).isMultiple(of: $0.0 )} }
|
||||
.makeIterator()
|
||||
|
||||
print(s.next())
|
||||
|
||||
*/
|
||||
|
||||
var step = 0
|
||||
var time = 0
|
||||
|
||||
outer: while true {
|
||||
time += step
|
||||
|
||||
step = 1
|
||||
for (bus, position) in busLines {
|
||||
guard (time + position).isMultiple(of: bus) else { continue outer }
|
||||
step *= bus
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
print("part2", time)
|
93
2020/day14/main.swift
Normal file
93
2020/day14/main.swift
Normal file
|
@ -0,0 +1,93 @@
|
|||
import Foundation
|
||||
let input = loadData(day: 14)
|
||||
|
||||
class Problem {
|
||||
let scanner: Scanner
|
||||
|
||||
/// Each bit where the mask is "1" is set here
|
||||
var maskBits: UInt64 = 0
|
||||
|
||||
/// Each bit where the mask is "X" is set here
|
||||
var maskUsed: UInt64 = 0
|
||||
var mem: [UInt64:UInt64] = [:]
|
||||
|
||||
var writeMem: (Problem, UInt64, UInt64) -> Void
|
||||
|
||||
init(_ input: String, writeMem: @escaping (Problem, UInt64, UInt64) -> Void) {
|
||||
scanner = Scanner(string: input)
|
||||
self.writeMem = writeMem
|
||||
}
|
||||
|
||||
func run() {
|
||||
while !scanner.isAtEnd {
|
||||
if scanner.string("mask = "), let mask = scanner.scanCharacters(from: Self.maskSet) {
|
||||
readMask(mask)
|
||||
} else if scanner.string("mem["), let addr = scanner.scanUInt64(), scanner.string("] = "), let value = scanner.scanUInt64() {
|
||||
writeMem(self, addr, value)
|
||||
} else {
|
||||
assertionFailure("Invalid input")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print("sum", mem.values.reduce(0, +))
|
||||
}
|
||||
|
||||
private func readMask(_ mask: String) {
|
||||
assert(mask.count == 36)
|
||||
|
||||
maskBits = 0
|
||||
maskUsed = 0
|
||||
|
||||
for char in mask {
|
||||
maskBits <<= 1
|
||||
maskUsed <<= 1
|
||||
|
||||
switch char {
|
||||
case "1": maskBits |= 1
|
||||
case "0": break
|
||||
case "X": maskUsed |= 1
|
||||
default: assertionFailure("Invalid character in mask")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static private let maskSet = CharacterSet(charactersIn: "01X")
|
||||
}
|
||||
|
||||
|
||||
|
||||
let part1 = Problem(input) { problem, addr, value in
|
||||
problem.mem[addr] = (value & problem.maskUsed) | problem.maskBits
|
||||
}
|
||||
part1.run()
|
||||
|
||||
|
||||
|
||||
func possibleValues(_ mask: UInt64) -> [UInt64] {
|
||||
var values: [UInt64] = []
|
||||
var mask = mask
|
||||
for i in 0..<36 {
|
||||
if mask & 1 != 0 {
|
||||
let bit: UInt64 = 1 << i
|
||||
if values.isEmpty {
|
||||
values.append(0)
|
||||
values.append(bit)
|
||||
} else {
|
||||
values.append(contentsOf: values.map { $0 | bit })
|
||||
}
|
||||
}
|
||||
mask >>= 1
|
||||
}
|
||||
|
||||
return values
|
||||
}
|
||||
|
||||
let part2 = Problem(input) { problem, addr, value in
|
||||
for i in possibleValues(problem.maskUsed) {
|
||||
let effective = i | ((addr | problem.maskBits) & ~problem.maskUsed)
|
||||
problem.mem[effective] = value
|
||||
}
|
||||
}
|
||||
|
||||
part2.run()
|
36
2020/day15/main.swift
Normal file
36
2020/day15/main.swift
Normal file
|
@ -0,0 +1,36 @@
|
|||
import Foundation
|
||||
|
||||
let input = [16,1,0,18,12,14,19]
|
||||
|
||||
var memory: [Int: (Int, Int?)] = [:]
|
||||
var last = -1
|
||||
|
||||
for (round, num) in input.enumerated() {
|
||||
memory[num] = (round, nil)
|
||||
last = num
|
||||
}
|
||||
|
||||
func lastRound(for num: Int) -> Int? {
|
||||
guard let (first, second) = memory[num] else { return nil }
|
||||
if let second = second { return second }
|
||||
return first
|
||||
}
|
||||
|
||||
for round in input.count..<30000000 {
|
||||
let (first, second) = memory[last]!
|
||||
|
||||
if let second = second {
|
||||
last = second - first
|
||||
} else {
|
||||
last = 0
|
||||
}
|
||||
|
||||
if let prev = lastRound(for: last) {
|
||||
memory[last] = (prev, round)
|
||||
} else {
|
||||
memory[last] = (round, nil)
|
||||
}
|
||||
}
|
||||
|
||||
print(last)
|
||||
|
116
2020/day16/main.swift
Normal file
116
2020/day16/main.swift
Normal file
|
@ -0,0 +1,116 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 16)
|
||||
let scanner = Scanner(string: input)
|
||||
|
||||
extension Scanner {
|
||||
func scanRange() -> ClosedRange<Int>? {
|
||||
guard let low = scanInt(),
|
||||
string("-"),
|
||||
let high = scanInt()
|
||||
else { return nil }
|
||||
return low...high
|
||||
}
|
||||
|
||||
func scanFieldDefinition() -> (String, ClosedRange<Int>, ClosedRange<Int>)? {
|
||||
var location = scanLocation
|
||||
guard let name = scanUpToString(":"),
|
||||
string(":"),
|
||||
let first = scanRange(),
|
||||
string("or"),
|
||||
let second = scanRange()
|
||||
else {
|
||||
scanLocation = location
|
||||
return nil
|
||||
}
|
||||
return (name, first, second)
|
||||
}
|
||||
|
||||
func scanFieldDefinitions() -> [(String, ClosedRange<Int>, ClosedRange<Int>)] {
|
||||
var result = [(String, ClosedRange<Int>, ClosedRange<Int>)]()
|
||||
while let field = scanFieldDefinition() {
|
||||
result.append(field)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func scanTicket() -> [Int]? {
|
||||
var result = [Int]()
|
||||
repeat {
|
||||
guard let field = scanInt() else { return nil }
|
||||
result.append(field)
|
||||
} while string(",")
|
||||
return result
|
||||
}
|
||||
|
||||
func scanYourTicket() -> [Int]? {
|
||||
guard string("your ticket:"),
|
||||
let ticket = scanTicket()
|
||||
else { return nil }
|
||||
return ticket
|
||||
}
|
||||
|
||||
func scanNearbyTickets() -> [[Int]]? {
|
||||
guard string("nearby tickets:") else { return nil }
|
||||
var result = [[Int]]()
|
||||
while !isAtEnd {
|
||||
guard let ticket = scanTicket() else { return nil }
|
||||
result.append(ticket)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
let definitions = scanner.scanFieldDefinitions()
|
||||
guard let yourTicket = scanner.scanYourTicket(),
|
||||
let nearbyTickets = scanner.scanNearbyTickets()
|
||||
else { fatalError() }
|
||||
|
||||
|
||||
func isValid(_ value: Int) -> Bool {
|
||||
definitions.contains {
|
||||
$0.1.contains(value) || $0.2.contains(value)
|
||||
}
|
||||
}
|
||||
|
||||
func isValid(_ ticket: [Int]) -> Bool {
|
||||
ticket.allSatisfy(isValid)
|
||||
}
|
||||
|
||||
let invalidSums = nearbyTickets
|
||||
.flatten()
|
||||
.filter( { !isValid($0) } )
|
||||
.reduce(0, +)
|
||||
|
||||
print(invalidSums)
|
||||
|
||||
|
||||
var possibleFields: [Set<String>] = Array(repeating: Set(definitions.map { $0.0 }), count: yourTicket.count)
|
||||
|
||||
for ticket in nearbyTickets where isValid(ticket) {
|
||||
for (index, value) in ticket.enumerated() {
|
||||
for (name, first, second) in definitions {
|
||||
if !(first.contains(value) || second.contains(value)) {
|
||||
possibleFields[index].remove(name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for index in possibleFields.indices.sorted(by: { possibleFields[$0].count < possibleFields[$1].count }) {
|
||||
guard possibleFields[index].count == 1, let key = possibleFields[index].first else { fatalError() }
|
||||
for i in possibleFields.indices where i != index {
|
||||
possibleFields[i].remove(key)
|
||||
}
|
||||
}
|
||||
|
||||
let mapping = possibleFields.map { $0.first! }
|
||||
|
||||
let result = mapping.enumerated()
|
||||
.map { ($0.element, yourTicket[$0.offset]) }
|
||||
.filter { $0.0.hasPrefix("departure") }
|
||||
.map { $0.1 }
|
||||
.reduce(1, *)
|
||||
|
||||
print(result)
|
100
2020/day17/main.swift
Normal file
100
2020/day17/main.swift
Normal file
|
@ -0,0 +1,100 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 17).lines()
|
||||
|
||||
struct Coordinate: Hashable {
|
||||
var x, y, z, w: Int
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct Cube {
|
||||
var cube: [Coordinate: Bool] = [:]
|
||||
var minX = 0
|
||||
var maxX = 0
|
||||
var minY = 0
|
||||
var maxY = 0
|
||||
var minZ = 0
|
||||
var maxZ = 0
|
||||
var minW = 0
|
||||
var maxW = 0
|
||||
|
||||
func neighbors(_ c: Coordinate) -> Int {
|
||||
var count = 0
|
||||
for xOffset in -1...1 {
|
||||
for yOffset in -1...1 {
|
||||
for zOffset in -1...1 {
|
||||
for wOffset in -1 ... 1 {
|
||||
guard !(xOffset == 0 && yOffset == 0 && zOffset == 0 && wOffset == 0) else { continue }
|
||||
let current = Coordinate(x: c.x + xOffset, y: c.y + yOffset, z: c.z + zOffset, w: c.w + wOffset)
|
||||
if let value = cube[current], value {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
subscript(_ x: Int, _ y : Int, _ z : Int, _ w : Int ) -> Bool {
|
||||
get {
|
||||
cube[Coordinate(x: x, y: y, z: z, w: w)] ?? false
|
||||
}
|
||||
|
||||
set {
|
||||
cube[Coordinate(x: x, y: y, z: z, w: w)] = newValue
|
||||
if newValue {
|
||||
minX = min(x, minX)
|
||||
minY = min(y, minY)
|
||||
minZ = min(z, minZ)
|
||||
maxX = max(x, maxX)
|
||||
maxY = max(y, maxY)
|
||||
maxZ = max(z, maxZ)
|
||||
minW = min(w, minW)
|
||||
maxW = max(w, maxW)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var cube = Cube()
|
||||
|
||||
func cycle() -> Cube {
|
||||
var result = cube
|
||||
|
||||
for x in cube.minX - 1 ... cube.maxX + 1 {
|
||||
for y in cube.minY - 1 ... cube.maxY + 1 {
|
||||
for z in cube.minZ - 1 ... cube.maxZ + 1 {
|
||||
for w in cube.minW - 1 ... cube.maxW + 1 {
|
||||
let n = cube.neighbors(Coordinate(x: x, y: y, z: z, w: w))
|
||||
if cube[x, y, z, w] {
|
||||
if n < 2 || n > 3 {
|
||||
result[x, y, z, w] = false
|
||||
}
|
||||
} else {
|
||||
if n == 3 {
|
||||
result[x, y, z, w] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
for (y, line) in input.enumerated() {
|
||||
for (x, char) in line.enumerated() {
|
||||
cube[x, y, 0, 0] = char == "#"
|
||||
}
|
||||
}
|
||||
|
||||
for _ in 0..<6 {
|
||||
cube = cycle()
|
||||
}
|
||||
|
||||
print(cube.cube.values.reduce(0, { $0 + ($1 ? 1 : 0) }))
|
48
2020/day18/main.swift
Normal file
48
2020/day18/main.swift
Normal file
|
@ -0,0 +1,48 @@
|
|||
import Foundation
|
||||
let input = loadData(day: 18)
|
||||
let scanner = Scanner(string: input)
|
||||
|
||||
extension Scanner {
|
||||
func primary() -> Int? {
|
||||
if let num = scanInt() {
|
||||
return num
|
||||
}
|
||||
|
||||
if string("(") {
|
||||
let result = expression()
|
||||
if !string(")") {
|
||||
fatalError()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func op() -> String? {
|
||||
scanString("+") ?? scanString("*")
|
||||
}
|
||||
|
||||
func expression() -> Int? {
|
||||
guard var result = addition() else { return nil }
|
||||
while string("*"), let second = addition() {
|
||||
result *= second
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func addition() -> Int? {
|
||||
guard var result = primary() else { return nil }
|
||||
while string("+"), let second = primary() {
|
||||
result += second
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
var result = 0
|
||||
while let e = scanner.expression() {
|
||||
result += e
|
||||
}
|
||||
|
||||
print(result)
|
147
2020/day19/main.swift
Normal file
147
2020/day19/main.swift
Normal file
|
@ -0,0 +1,147 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 19)
|
||||
let scanner = Scanner(string: input)
|
||||
scanner.charactersToBeSkipped = .whitespaces
|
||||
|
||||
enum Rule: Equatable {
|
||||
case character(Character)
|
||||
indirect case sequence(Rule, Rule)
|
||||
indirect case alternative(Rule, Rule)
|
||||
case reference(Int)
|
||||
}
|
||||
|
||||
|
||||
typealias RuleSet = [Int: Rule]
|
||||
|
||||
extension Scanner {
|
||||
func parseRuleSet() -> RuleSet {
|
||||
var result: [Int: Rule] = [:]
|
||||
while !string("\n") {
|
||||
guard let (index, rule) = parseRuleDefinition() else { fatalError() }
|
||||
result[index] = rule
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func parseRuleDefinition() -> (Int, Rule)? {
|
||||
guard let label = parseLabel(),
|
||||
let rule = parseRule(),
|
||||
string("\n")
|
||||
else { return nil }
|
||||
return (label, rule)
|
||||
}
|
||||
|
||||
func parseLabel() -> Int? {
|
||||
guard let num = scanInt(),
|
||||
string(":")
|
||||
else { return nil }
|
||||
return num
|
||||
}
|
||||
|
||||
func parseRule() -> Rule? {
|
||||
if string("\""), let character = scanCharacter(), string("\"") {
|
||||
return .character(character)
|
||||
}
|
||||
|
||||
guard let sequence = parseSequence() else { return nil }
|
||||
|
||||
if string("|"), let rhs = parseSequence() {
|
||||
return .alternative(sequence, rhs)
|
||||
}
|
||||
|
||||
return sequence
|
||||
}
|
||||
|
||||
func parseReference() -> Rule? {
|
||||
guard let num = scanInt() else { return nil }
|
||||
return .reference(num)
|
||||
}
|
||||
|
||||
func parseSequence() -> Rule? {
|
||||
guard var sequence = parseReference() else {
|
||||
return nil
|
||||
}
|
||||
|
||||
while let rhs = parseReference() {
|
||||
sequence = .sequence(sequence, rhs)
|
||||
}
|
||||
|
||||
return sequence
|
||||
}
|
||||
}
|
||||
|
||||
let rules = scanner.parseRuleSet()
|
||||
|
||||
extension Rule {
|
||||
func matches(rules: RuleSet, _ s: Substring) -> Set<Substring> {
|
||||
switch self {
|
||||
case .character(let ch):
|
||||
if s.first == ch {
|
||||
return [s.dropFirst()]
|
||||
}
|
||||
|
||||
return []
|
||||
|
||||
case let .sequence(first, second):
|
||||
let firstMatches = first.matches(rules: rules, s)
|
||||
return Set(firstMatches.flatMap { second.matches(rules: rules, $0) })
|
||||
|
||||
case let .alternative(first, second):
|
||||
let firstMatch = first.matches(rules: rules, s)
|
||||
let secondMatch = second.matches(rules: rules, s)
|
||||
|
||||
return firstMatch.union(secondMatch)
|
||||
|
||||
case .reference(let index):
|
||||
return rules[index]!.matches(rules: rules, s)
|
||||
}
|
||||
}
|
||||
|
||||
func matches(rules: RuleSet, _ s: String) -> Bool {
|
||||
let result = matches(rules: rules, s[...])
|
||||
return result.contains("")
|
||||
}
|
||||
}
|
||||
|
||||
extension Scanner {
|
||||
func scanLine() -> String? {
|
||||
guard let result = scanUpToCharacters(from: .newlines),
|
||||
scanCharacters(from: .newlines) != nil else {
|
||||
return nil
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func readLines() -> [String] {
|
||||
|
||||
var lines = [String]()
|
||||
while let line = scanner.scanLine() {
|
||||
lines.append(line)
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let messages = scanner.readLines()
|
||||
|
||||
let start = Rule.reference(0)
|
||||
|
||||
print("part 1:", messages.lazy.filter { start.matches(rules: rules, $0) }.count)
|
||||
|
||||
let changedRules = """
|
||||
8: 42 | 42 8
|
||||
11: 42 31 | 42 11 31
|
||||
|
||||
|
||||
"""
|
||||
|
||||
let changeScanner = Scanner(string: changedRules)
|
||||
changeScanner.charactersToBeSkipped = .whitespaces
|
||||
let ruleUpdates = changeScanner.parseRuleSet()
|
||||
|
||||
let newRules = rules.merging(ruleUpdates) { $1 }
|
||||
|
||||
print("part 2:", messages.filter { start.matches(rules: newRules, $0) }.count)
|
39
2020/day2/main.swift
Normal file
39
2020/day2/main.swift
Normal file
|
@ -0,0 +1,39 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 2)
|
||||
|
||||
var valids = 0
|
||||
var valid2 = 0
|
||||
|
||||
var scanner = Scanner(string: input)
|
||||
while !scanner.isAtEnd {
|
||||
guard let min = scanner.scanInt(),
|
||||
scanner.scanString("-") != nil,
|
||||
let max = scanner.scanInt(),
|
||||
let character = scanner.scanCharacter(),
|
||||
scanner.scanString(":") != nil,
|
||||
let password = scanner.scanUpToCharacters(from: .newlines)
|
||||
else {
|
||||
fatalError("Invalid input");
|
||||
}
|
||||
|
||||
|
||||
let count = password.lazy.filter { $0 == character }.count
|
||||
|
||||
if min <= count && count <= max {
|
||||
print("valid", min, max, character, password)
|
||||
valids += 1
|
||||
}
|
||||
|
||||
let first = password.index(password.startIndex, offsetBy: min - 1, limitedBy: password.endIndex).map { password[$0] }
|
||||
let second = password.index(password.startIndex, offsetBy: max - 1, limitedBy: password.endIndex).map { password[$0] }
|
||||
|
||||
if (first == character || second == character) && first != second {
|
||||
print("valid 2", password)
|
||||
valid2 += 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
print("Valid old", valids)
|
||||
print("Valid new", valid2)
|
272
2020/day20/main.swift
Normal file
272
2020/day20/main.swift
Normal file
|
@ -0,0 +1,272 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 20)
|
||||
let scanner = Scanner(string: input)
|
||||
|
||||
|
||||
struct Tile {
|
||||
var id: Int
|
||||
var imageData: [Bool]
|
||||
var size: Int
|
||||
|
||||
subscript (_ x: Int, _ y: Int) -> Bool {
|
||||
get { imageData[x + y * size] }
|
||||
set { imageData[x + y * size] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Scanner {
|
||||
func tile() -> Tile? {
|
||||
guard string("Tile"),
|
||||
let id = scanInt(),
|
||||
string(":"),
|
||||
let (image, size) = imageData()
|
||||
else { return nil }
|
||||
return Tile(id: id, imageData: image, size: size)
|
||||
}
|
||||
|
||||
func imageData() -> ([Bool], Int)? {
|
||||
var result: [Bool] = []
|
||||
let set = CharacterSet(charactersIn: "#.")
|
||||
var width: Int? = nil
|
||||
while let line = scanCharacters(from: set) {
|
||||
assert(width == nil || line.count == width)
|
||||
width = line.count
|
||||
result.append(contentsOf: line.map { $0 == "#" })
|
||||
}
|
||||
|
||||
guard let w = width else { return nil }
|
||||
|
||||
return (result, w)
|
||||
}
|
||||
|
||||
func tileSet() -> [Int: Tile]? {
|
||||
var result: [Int: Tile] = [:]
|
||||
while !isAtEnd {
|
||||
guard let tile = self.tile() else { return nil }
|
||||
result[tile.id] = tile
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
let tilesById = scanner.tileSet()!
|
||||
|
||||
struct TileReference: Hashable {
|
||||
enum Rotation: CaseIterable {
|
||||
case rotate0, rotate90, rotate180, rotate270
|
||||
}
|
||||
|
||||
var id: Int
|
||||
var flipped: Bool
|
||||
var rotation: Rotation
|
||||
|
||||
subscript (x: Int, y: Int) -> Bool {
|
||||
get {
|
||||
let tile = tilesById[id]!
|
||||
|
||||
var coord = flipped ? (x: tile.size - 1 - x, y: y) : (x: x, y: y)
|
||||
coord = rotation.get(x: coord.x, y: coord.y, size: tile.size)
|
||||
|
||||
return tile[coord.x, coord.y]
|
||||
}
|
||||
}
|
||||
|
||||
var end: Int { tilesById[id]!.size - 1 }
|
||||
}
|
||||
|
||||
extension TileReference.Rotation {
|
||||
func get(x: Int, y: Int, size: Int) -> (x: Int, y: Int) {
|
||||
let e = size - 1
|
||||
switch self {
|
||||
case .rotate0: return (x, y)
|
||||
case .rotate90: return (y, e - x)
|
||||
case .rotate180: return (x, e - y)
|
||||
case .rotate270: return (e - y, x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Board {
|
||||
struct Cell {
|
||||
var possible: Array<TileReference>
|
||||
}
|
||||
|
||||
var size: Int
|
||||
var cells: [Cell]
|
||||
|
||||
init<T>(tiles: T) where T: Sequence, T.Element == Int {
|
||||
let orientations = [true, false].flatMap { flipped in TileReference.Rotation.allCases.map { (flipped, $0) } }
|
||||
let allOptions = tiles.flatMap { id in orientations.map { TileReference(id: id, flipped: $0.0, rotation: $0.1 ) } }
|
||||
size = Int(sqrt(Double(tilesById.count)))
|
||||
cells = Array(repeating: Cell(possible: allOptions), count: size*size)
|
||||
assert(size * size == tilesById.count)
|
||||
}
|
||||
|
||||
subscript(x: Int, y: Int) -> Cell {
|
||||
get { cells[x + y * size] }
|
||||
set { cells[x + y * size] = newValue }
|
||||
}
|
||||
|
||||
func coordinate(_ cell: Int) -> (x: Int, y: Int) {
|
||||
let (y, x) = cell.quotientAndRemainder(dividingBy: size)
|
||||
return (x, y)
|
||||
}
|
||||
|
||||
func solve(startingAt: Int = 0) -> Board? {
|
||||
if startingAt >= cells.count { return self }
|
||||
|
||||
let coord = coordinate(startingAt)
|
||||
let left = coord.x > 0 ? self[coord.x - 1, coord.y].chosen! : nil
|
||||
let above = coord.y > 0 ? self[coord.x, coord.y - 1].chosen! : nil
|
||||
|
||||
func matchLeft(_ ref: TileReference) -> Bool {
|
||||
guard let left = left else { return true }
|
||||
return (0...ref.end).allSatisfy { left[left.end, $0] == ref[0, $0] }
|
||||
}
|
||||
|
||||
func matchAbove(_ ref: TileReference) -> Bool {
|
||||
guard let above = above else { return true }
|
||||
return (0...ref.end).allSatisfy { above[$0, above.end] == ref[$0, 0] }
|
||||
}
|
||||
|
||||
for option in cells[startingAt].possible.lazy.filter({ matchLeft($0) && matchAbove($0) }) {
|
||||
var result = self
|
||||
result.cells[startingAt].possible = [option]
|
||||
|
||||
let next = startingAt + 1
|
||||
|
||||
for cell in next..<cells.count {
|
||||
result.cells[cell].possible = result.cells[cell].possible.filter {
|
||||
return $0.id != option.id
|
||||
}
|
||||
|
||||
if result.cells[cell].possible.isEmpty {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
if let solution = result.solve(startingAt: next) {
|
||||
return solution
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Board.Cell {
|
||||
var chosen: TileReference? {
|
||||
guard let result = possible.first, possible.count == 1 else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
let start = Date()
|
||||
guard let solution = Board(tiles: tilesById.keys).solve() else { fatalError() }
|
||||
let end = Date()
|
||||
|
||||
print("Took", end.timeIntervalSince(start))
|
||||
|
||||
let e = solution.size - 1
|
||||
|
||||
print(solution[0,0].chosen!.id)
|
||||
|
||||
print(
|
||||
solution[0,0].chosen!.id *
|
||||
solution[e,0].chosen!.id *
|
||||
solution[0,e].chosen!.id *
|
||||
solution[e,e].chosen!.id
|
||||
)
|
||||
|
||||
extension Board {
|
||||
struct CompleteImage {
|
||||
let board: Board
|
||||
var flipped = false
|
||||
var rotation = TileReference.Rotation.rotate0
|
||||
}
|
||||
|
||||
var completeImage: CompleteImage {
|
||||
CompleteImage(board: self)
|
||||
}
|
||||
|
||||
func completeImage(flipped: Bool, rotation: TileReference.Rotation) -> CompleteImage {
|
||||
CompleteImage(board: self, flipped: flipped, rotation: rotation)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Board.CompleteImage {
|
||||
var size: Int {
|
||||
board.size * (board.cells[0].chosen!.end - 1)
|
||||
}
|
||||
|
||||
subscript(x: Int, y: Int) -> Bool {
|
||||
get {
|
||||
var coord = flipped ? (x: size - 1 - x, y: y) : (x: x, y: y)
|
||||
coord = rotation.get(x: coord.x, y: coord.y, size: size)
|
||||
|
||||
let tileSize = board.cells[0].chosen!.end - 1
|
||||
let (tileX, offsetX) = coord.x.quotientAndRemainder(dividingBy: tileSize)
|
||||
let (tileY, offsetY) = coord.y.quotientAndRemainder(dividingBy: tileSize)
|
||||
let tile = board[tileX, tileY].chosen!
|
||||
return tile[offsetX + 1, offsetY + 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for y in 0..<solution.completeImage.size {
|
||||
for x in 0..<solution.completeImage.size {
|
||||
print(solution.completeImage[x, y] ? "#" : ".", terminator: "")
|
||||
}
|
||||
print()
|
||||
}
|
||||
|
||||
|
||||
extension Board.CompleteImage {
|
||||
func seaMonster(x: Int, y: Int) -> Bool {
|
||||
return self[x + 18, y] &&
|
||||
self[x + 0, y + 1] && self[x + 5, y + 1] && self[x + 6, y + 1] && self[x + 11, y + 1] && self[x + 12, y + 1] && self[x + 17, y + 1] && self[x + 18, y + 1] && self[x + 19, y + 1] &&
|
||||
self[x + 1, y + 2] && self[x + 4, y + 2] && self[x + 7, y + 2] && self[x + 10, y + 2] && self[x + 13, y + 2] && self[x + 16, y + 2]
|
||||
}
|
||||
|
||||
func countMonsters() -> Int {
|
||||
var count = 0
|
||||
for y in 0..<size - 2 {
|
||||
for x in 0..<size - 19 {
|
||||
if seaMonster(x: x, y: y) {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func countOnes() -> Int {
|
||||
var count = 0
|
||||
for y in 0..<size {
|
||||
for x in 0..<size {
|
||||
count += self[x, y] ? 1 : 0
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
}
|
||||
|
||||
let ones = solution.completeImage.countOnes()
|
||||
outer: for flipped in [true, false] {
|
||||
for rotation in TileReference.Rotation.allCases {
|
||||
let monsters = solution.completeImage(flipped: flipped, rotation: rotation).countMonsters()
|
||||
if monsters > 0 {
|
||||
let monsterTiles = monsters * 15
|
||||
let result = ones - monsterTiles
|
||||
print(result)
|
||||
break outer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
91
2020/day21/main.swift
Normal file
91
2020/day21/main.swift
Normal file
|
@ -0,0 +1,91 @@
|
|||
import Foundation
|
||||
let input = loadData(day: 21)
|
||||
|
||||
let scanner = Scanner(string: input)
|
||||
scanner.charactersToBeSkipped = .whitespaces
|
||||
|
||||
extension Scanner {
|
||||
func ingredient() -> String? {
|
||||
scanUpToCharacters(from: .whitespaces)
|
||||
}
|
||||
|
||||
func allergens() -> Set<String>? {
|
||||
guard string("(contains") else { return nil }
|
||||
var result: Set<String> = []
|
||||
let end = CharacterSet(charactersIn: ",)")
|
||||
repeat {
|
||||
guard let allergen = scanUpToCharacters(from: end) else { return nil }
|
||||
result.insert(allergen)
|
||||
} while string(",")
|
||||
guard string(")") else { return nil }
|
||||
return result
|
||||
}
|
||||
|
||||
func end() -> Set<String>? {
|
||||
let allergens = self.allergens()
|
||||
guard string("\n") else { return nil }
|
||||
return allergens ?? []
|
||||
}
|
||||
|
||||
typealias Food = (ingredients: Set<String>, allergens: Set<String>)
|
||||
|
||||
func food() -> Food? {
|
||||
var ingredients = Set<String>()
|
||||
while true {
|
||||
guard let ingredient = self.ingredient() else { return nil }
|
||||
ingredients.insert(ingredient)
|
||||
|
||||
if let end = self.end() {
|
||||
return (ingredients, end)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func foods() -> [Food] {
|
||||
var result: [Food] = []
|
||||
while !isAtEnd, let food = self.food() {
|
||||
result.append(food)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
let data = scanner.foods()
|
||||
|
||||
var possibleIngredientsByAllergen: [String: Set<String>] = [:]
|
||||
var allIngredients: Set<String> = []
|
||||
var allergens: [(String, String)] = []
|
||||
|
||||
for (ingredients, allergens) in data {
|
||||
allIngredients.formUnion(ingredients)
|
||||
for allergen in allergens {
|
||||
if let possible = possibleIngredientsByAllergen[allergen] {
|
||||
possibleIngredientsByAllergen[allergen] = possible.intersection(ingredients)
|
||||
} else {
|
||||
possibleIngredientsByAllergen[allergen] = ingredients
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while !possibleIngredientsByAllergen.isEmpty {
|
||||
for (allergen, possible) in possibleIngredientsByAllergen where possible.count == 1 {
|
||||
let ingredient = possible.first!
|
||||
allIngredients.remove(ingredient)
|
||||
possibleIngredientsByAllergen.removeValue(forKey: allergen)
|
||||
allergens.append((allergen, ingredient))
|
||||
for key in possibleIngredientsByAllergen.keys {
|
||||
possibleIngredientsByAllergen[key]?.remove(ingredient)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let count = data.reduce(0) { $0 + $1.ingredients.intersection(allIngredients).count }
|
||||
|
||||
print("part 1:", count)
|
||||
|
||||
let canonicalDangerousList = allergens
|
||||
.sorted { $0.0 < $1.0 }
|
||||
.map { $0.1 }
|
||||
.joined(separator: ",")
|
||||
|
||||
print("part 2:", canonicalDangerousList)
|
87
2020/day22/main.swift
Normal file
87
2020/day22/main.swift
Normal file
|
@ -0,0 +1,87 @@
|
|||
import Foundation
|
||||
let data = loadData(day: 22)
|
||||
let scanner = Scanner(string: data)
|
||||
|
||||
|
||||
guard scanner.string("Player 1:") else { fatalError() }
|
||||
let p1 = scanner.integers()
|
||||
var player1Deck = p1
|
||||
|
||||
guard scanner.string("Player 2:") else { fatalError() }
|
||||
let p2 = scanner.integers()
|
||||
var player2Deck = p2
|
||||
|
||||
assert(player1Deck.count == player2Deck.count)
|
||||
|
||||
while !player1Deck.isEmpty && !player2Deck.isEmpty {
|
||||
let a = player1Deck.removeFirst()
|
||||
let b = player2Deck.removeFirst()
|
||||
|
||||
if a > b {
|
||||
player1Deck.append(contentsOf: [a, b])
|
||||
} else {
|
||||
player2Deck.append(contentsOf: [b, a])
|
||||
}
|
||||
}
|
||||
|
||||
func calculateScore(_ deck: [Int]) -> Int {
|
||||
deck.reversed().enumerated().reduce(0) { $0 + $1.element * ($1.offset + 1) }
|
||||
}
|
||||
|
||||
if player2Deck.isEmpty {
|
||||
print("Player 1 wins", calculateScore(player1Deck))
|
||||
} else {
|
||||
print("Player 2 wins", calculateScore(player2Deck))
|
||||
}
|
||||
|
||||
struct PlayedDeck: Hashable {
|
||||
let player1: [Int]
|
||||
let player2: [Int]
|
||||
}
|
||||
var playedDecks: Set<PlayedDeck> = []
|
||||
|
||||
|
||||
func playGame(deck1: [Int], deck2: [Int]) -> (winner: Bool, score: Int) {
|
||||
var deck1 = deck1
|
||||
var deck2 = deck2
|
||||
var playedDecks: Set<PlayedDeck> = []
|
||||
|
||||
while !deck1.isEmpty && !deck2.isEmpty {
|
||||
if !playedDecks.insert(PlayedDeck(player1: deck1, player2: deck2)).inserted {
|
||||
return (true, calculateScore(deck1))
|
||||
}
|
||||
playRound(deck1: &deck1, deck2: &deck2)
|
||||
}
|
||||
|
||||
let winner = deck2.isEmpty
|
||||
return (winner, winner ? calculateScore(deck1) : calculateScore(deck2))
|
||||
}
|
||||
|
||||
func playRound(deck1: inout [Int], deck2: inout [Int]) {
|
||||
let a = deck1.removeFirst()
|
||||
let b = deck2.removeFirst()
|
||||
|
||||
let winner: Bool
|
||||
if a <= deck1.count && b <= deck2.count {
|
||||
winner = playGame(deck1: Array(deck1[0..<a]), deck2: Array(deck2[0..<b])).winner
|
||||
} else {
|
||||
winner = a > b
|
||||
}
|
||||
|
||||
if winner {
|
||||
deck1.append(contentsOf: [a, b])
|
||||
} else {
|
||||
deck2.append(contentsOf: [b, a])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
player1Deck = p1
|
||||
player2Deck = p2
|
||||
|
||||
let (winner, score) = playGame(deck1: p1, deck2: p2)
|
||||
if winner {
|
||||
print("Player 1 wins", score)
|
||||
} else {
|
||||
print("Player 2 wins", score)
|
||||
}
|
112
2020/day23/main.swift
Normal file
112
2020/day23/main.swift
Normal file
|
@ -0,0 +1,112 @@
|
|||
var nodesByValue: [Node?] = Array(repeating: nil, count: 1000001)
|
||||
|
||||
final class Node {
|
||||
var next: Node!
|
||||
var value: Int
|
||||
|
||||
init(value: Int, next: Node? = nil) {
|
||||
self.value = value
|
||||
self.next = next
|
||||
}
|
||||
|
||||
static func make(_ values: [Int]) -> Node {
|
||||
precondition(!values.isEmpty)
|
||||
|
||||
let first = Node(value: values[0])
|
||||
nodesByValue[values[0]] = first
|
||||
first.next = first
|
||||
|
||||
var current = first
|
||||
for value in values.dropFirst() {
|
||||
let new = Node(value: value, next: first)
|
||||
nodesByValue[value] = new
|
||||
current.next = new
|
||||
current = new
|
||||
}
|
||||
|
||||
for value in 10...1000000 {
|
||||
let new = Node(value: value, next: first)
|
||||
nodesByValue[value] = new
|
||||
current.next = new
|
||||
current = new
|
||||
}
|
||||
|
||||
return first
|
||||
}
|
||||
|
||||
func find(value: Int) -> Node? {
|
||||
return nodesByValue[value]
|
||||
}
|
||||
}
|
||||
|
||||
let input = [9, 5, 2, 3, 1, 6, 4, 8, 7]
|
||||
let max = 1000000
|
||||
//let max = input.max()!
|
||||
|
||||
let node = Node.make(input)
|
||||
var selected = node
|
||||
|
||||
func rangeContains(value: Int, start: Node, end: Node) -> Bool {
|
||||
var current = start
|
||||
while current !== end.next {
|
||||
if current.value == value {
|
||||
return true
|
||||
}
|
||||
current = current.next
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func round() {
|
||||
let firstPick: Node = selected.next
|
||||
let lastPick: Node = firstPick.next.next
|
||||
|
||||
selected.next = lastPick.next
|
||||
|
||||
var destination = selected.value
|
||||
repeat {
|
||||
destination -= 1
|
||||
if destination < 1 {
|
||||
destination = max
|
||||
}
|
||||
} while rangeContains(value: destination, start: firstPick, end: lastPick)
|
||||
|
||||
let toInsert = lastPick.next.find(value: destination)!
|
||||
lastPick.next = toInsert.next
|
||||
toInsert.next = firstPick
|
||||
|
||||
selected = selected.next
|
||||
}
|
||||
|
||||
func printStack() {
|
||||
var current = node
|
||||
repeat {
|
||||
print(current === selected ? "(\(current.value))" : "\(current.value)", terminator: " ")
|
||||
current = current.next
|
||||
} while current !== node
|
||||
print()
|
||||
}
|
||||
|
||||
func showSolution() {
|
||||
let start = node.find(value: 1)!
|
||||
var one: Node = start.next
|
||||
while one !== start {
|
||||
print(one.value, terminator: "")
|
||||
one = one.next
|
||||
}
|
||||
print()
|
||||
|
||||
}
|
||||
|
||||
for i in 0..<10_000_000 {
|
||||
// print("\(i + 1)) ", terminator: "")
|
||||
// printStack()
|
||||
round()
|
||||
}
|
||||
|
||||
//print("Final: ", terminator: "")
|
||||
//printStack()
|
||||
//showSolution()
|
||||
|
||||
let one = node.find(value: 1)!
|
||||
print(one.next.value * one.next.next.value)
|
129
2020/day24/main.swift
Normal file
129
2020/day24/main.swift
Normal file
|
@ -0,0 +1,129 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 24)
|
||||
let scanner = Scanner(string: input)
|
||||
scanner.charactersToBeSkipped = nil
|
||||
|
||||
enum Direction: String, CaseIterable {
|
||||
case east = "e"
|
||||
case southEast = "se"
|
||||
case southWest = "sw"
|
||||
case west = "w"
|
||||
case northWest = "nw"
|
||||
case northEast = "ne"
|
||||
}
|
||||
|
||||
extension Scanner {
|
||||
func readDirection() -> Direction? {
|
||||
for dir in Direction.allCases {
|
||||
if string(dir.rawValue) {
|
||||
return dir
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
struct Coord: Hashable {
|
||||
var south: Int
|
||||
var east: Int
|
||||
|
||||
static let zero = Coord(south: 0, east: 0)
|
||||
|
||||
mutating func move(_ direction: Direction) {
|
||||
switch direction {
|
||||
case .east:
|
||||
east += 1
|
||||
case .southEast:
|
||||
south += 1
|
||||
|
||||
case .southWest:
|
||||
south += 1
|
||||
east -= 1
|
||||
|
||||
case .west:
|
||||
east -= 1
|
||||
|
||||
case .northWest:
|
||||
south -= 1
|
||||
|
||||
case .northEast:
|
||||
south -= 1
|
||||
east += 1
|
||||
}
|
||||
}
|
||||
|
||||
func neighbor(_ direction: Direction) -> Coord {
|
||||
var result = self
|
||||
result.move(direction)
|
||||
return result
|
||||
}
|
||||
|
||||
var neighbors: [Coord] {
|
||||
Direction.allCases.map(neighbor)
|
||||
}
|
||||
}
|
||||
|
||||
func readCoordinate() -> Coord {
|
||||
var current = Coord.zero
|
||||
while let direction = scanner.readDirection() {
|
||||
current.move(direction)
|
||||
}
|
||||
precondition(scanner.string("\n"))
|
||||
return current
|
||||
}
|
||||
|
||||
var floor: [Coord: Bool] = [:]
|
||||
var northWestCorner = Coord.zero
|
||||
var southEastCorner = Coord.zero
|
||||
|
||||
|
||||
func expandRange(toInclude coord: Coord) {
|
||||
northWestCorner.east = min(northWestCorner.east, coord.east)
|
||||
northWestCorner.south = min(northWestCorner.south, coord.south)
|
||||
|
||||
southEastCorner.east = max(southEastCorner.east, coord.east)
|
||||
southEastCorner.south = max(southEastCorner.south, coord.south)
|
||||
}
|
||||
|
||||
while !scanner.isAtEnd {
|
||||
let coord = readCoordinate()
|
||||
expandRange(toInclude: coord)
|
||||
|
||||
floor[coord, default: false].toggle()
|
||||
}
|
||||
|
||||
print("part 1:", floor.values.lazy.filter { $0 }.count)
|
||||
|
||||
func step() -> [Coord: Bool] {
|
||||
var result = floor
|
||||
|
||||
for east in (northWestCorner.east - 1)...(southEastCorner.east + 1) {
|
||||
for south in (northWestCorner.south - 1)...(southEastCorner.south + 1) {
|
||||
let coord = Coord(south: south, east: east)
|
||||
|
||||
let isBlack = floor[coord, default: false]
|
||||
|
||||
let blackNeighbors = coord.neighbors
|
||||
.lazy
|
||||
.map { floor[$0, default: false] }
|
||||
.filter { $0 }
|
||||
.count
|
||||
|
||||
if isBlack && (blackNeighbors == 0 || blackNeighbors > 2) {
|
||||
result[coord] = false
|
||||
} else if !isBlack && blackNeighbors == 2 {
|
||||
result[coord] = true
|
||||
expandRange(toInclude: coord)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
for _ in 0..<100 {
|
||||
floor = step()
|
||||
}
|
||||
|
||||
print("part 2:", floor.values.lazy.filter { $0 }.count)
|
35
2020/day25/main.swift
Normal file
35
2020/day25/main.swift
Normal file
|
@ -0,0 +1,35 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 25).lines().compactMap(Int.init)
|
||||
|
||||
func loop(subject: Int, times: Int) -> Int {
|
||||
var value = 1
|
||||
for _ in 0..<times {
|
||||
value = (value * subject) % 20201227
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func findLoopSize(subject: Int, expected: Int) -> Int {
|
||||
var value = 1
|
||||
for i in 0...Int.max {
|
||||
if value == expected {
|
||||
return i
|
||||
}
|
||||
|
||||
value = (value * subject) % 20201227
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
let sizes = input.map { findLoopSize(subject: 7, expected: $0) }
|
||||
print(sizes)
|
||||
|
||||
let (pub1, pub2) = (input[0], input[1])
|
||||
let (loop1, loop2) = (sizes[0], sizes[1])
|
||||
|
||||
let secret1 = loop(subject: pub2, times: loop1)
|
||||
let secret2 = loop(subject: pub1, times: loop2)
|
||||
|
||||
print(secret1, secret2)
|
||||
|
32
2020/day3/main.swift
Normal file
32
2020/day3/main.swift
Normal file
|
@ -0,0 +1,32 @@
|
|||
let input = loadData(day: 3).lines()
|
||||
|
||||
/// - returns true if a tree is at that position, false if it is empty
|
||||
func get(x: Int, y: Int) -> Bool {
|
||||
let line = input[y]
|
||||
let index = line.index(line.startIndex, offsetBy: x % line.count)
|
||||
return line[index] == "#"
|
||||
}
|
||||
|
||||
func calculate(dx: Int, dy: Int) -> Int {
|
||||
var x = 0
|
||||
var y = 0
|
||||
|
||||
var trees = 0
|
||||
|
||||
while y < input.count {
|
||||
if get(x: x, y: y) {
|
||||
trees += 1
|
||||
}
|
||||
|
||||
x += dx
|
||||
y += dy
|
||||
}
|
||||
|
||||
return trees
|
||||
}
|
||||
|
||||
let trees = calculate(dx: 3, dy: 1)
|
||||
print("trees", trees)
|
||||
|
||||
|
||||
print("combined", calculate(dx: 1, dy: 1) * calculate(dx: 3, dy: 1) * calculate(dx: 5, dy: 1) * calculate(dx: 7, dy: 1) * calculate(dx: 1, dy: 2))
|
99
2020/day4/main.swift
Normal file
99
2020/day4/main.swift
Normal file
|
@ -0,0 +1,99 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 4)
|
||||
|
||||
let scanner = Scanner(string: input)
|
||||
scanner.charactersToBeSkipped = nil
|
||||
|
||||
extension Scanner {
|
||||
func field() -> (String, String)? {
|
||||
guard let name = scanUpToString(":"),
|
||||
scanString(":") != nil,
|
||||
let value = scanUpToCharacters(from: .whitespacesAndNewlines)
|
||||
else { return nil }
|
||||
return (name, value)
|
||||
}
|
||||
|
||||
func passport() -> [String: String]? {
|
||||
var fields = [(String, String)]()
|
||||
while !isAtEnd && scanString("\n\n") == nil {
|
||||
_ = scanner.scanCharacters(from: .whitespacesAndNewlines)
|
||||
guard let field = field() else { return nil }
|
||||
fields.append(field)
|
||||
}
|
||||
return try? Dictionary(fields, uniquingKeysWith: { _, _ in throw NSError(domain: "error", code: 1, userInfo: nil) })
|
||||
}
|
||||
}
|
||||
|
||||
var valids = 0
|
||||
var valid2 = 0
|
||||
|
||||
let requiredFields = [
|
||||
"byr",
|
||||
"iyr",
|
||||
"eyr",
|
||||
"hgt",
|
||||
"hcl",
|
||||
"ecl",
|
||||
"pid",
|
||||
]
|
||||
|
||||
func validHeight(_ height: String) -> Bool {
|
||||
let scanner = Scanner(string: height)
|
||||
guard let number = scanner.scanInt() else { return false }
|
||||
if scanner.scanString("cm") != nil, 150...193 ~= number {
|
||||
return true
|
||||
}
|
||||
|
||||
if scanner.scanString("in") != nil, 59...76 ~= number {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func validHairColor(_ hcl: String) -> Bool {
|
||||
let scanner = Scanner(string: hcl)
|
||||
guard scanner.scanString("#") != nil else { return false }
|
||||
guard scanner.scanCharacters(from: CharacterSet(charactersIn: "0123456789abcdef"))?.count == 6 else { return false }
|
||||
return scanner.isAtEnd
|
||||
}
|
||||
|
||||
let validEyeColors: Set<String> = [
|
||||
"amb",
|
||||
"blu",
|
||||
"brn",
|
||||
"gry",
|
||||
"grn",
|
||||
"hzl",
|
||||
"oth"
|
||||
]
|
||||
|
||||
func isValidPassportId(_ pid: String) -> Bool {
|
||||
return pid.count == 9 && Int(pid) != nil
|
||||
}
|
||||
|
||||
while !scanner.isAtEnd {
|
||||
guard let passport = scanner.passport() else { fatalError() }
|
||||
print(passport)
|
||||
|
||||
let valid = requiredFields.allSatisfy { passport.keys.contains($0) }
|
||||
if valid {
|
||||
valids += 1
|
||||
}
|
||||
|
||||
guard let year = passport["byr"].flatMap(Int.init), 1920...2002 ~= year else { continue }
|
||||
guard let issueYear = passport["iyr"].flatMap(Int.init), 2010...2020 ~= issueYear else { continue }
|
||||
guard let expireYear = passport["eyr"].flatMap(Int.init), 2020...2030 ~= expireYear else { continue }
|
||||
guard let height = passport["hgt"], validHeight(height) else { continue }
|
||||
guard let hairColor = passport["hcl"], validHairColor(hairColor) else { continue }
|
||||
guard let eyeColor = passport["ecl"], validEyeColors.contains(eyeColor) else { continue }
|
||||
guard let pid = passport["pid"], isValidPassportId(pid) else { continue }
|
||||
|
||||
valid2 += 1
|
||||
|
||||
}
|
||||
|
||||
print("valids", valids)
|
||||
print("valid2", valid2)
|
||||
|
35
2020/day5/main.swift
Normal file
35
2020/day5/main.swift
Normal file
|
@ -0,0 +1,35 @@
|
|||
let input = loadData(day: 5).lines()
|
||||
|
||||
func decode(_ s: Substring, lower: Character, upper: Character, range: Range<Int>) -> (Int, Substring)
|
||||
{
|
||||
var range = range
|
||||
var start = s.startIndex
|
||||
while start != s.endIndex && (s[start] == lower || s[start] == upper) {
|
||||
let mid = (range.lowerBound + range.upperBound) / 2
|
||||
if s[start] == lower {
|
||||
range = range.lowerBound..<mid
|
||||
} else if s[start] == upper {
|
||||
range = mid..<range.upperBound
|
||||
}
|
||||
start = s.index(after: start)
|
||||
}
|
||||
|
||||
return (range.lowerBound, s[start...])
|
||||
}
|
||||
|
||||
func decodeSeat(_ s: String) -> Int {
|
||||
let (row, rest) = decode(s[...], lower: "F", upper: "B", range: 0..<128)
|
||||
let (column, _) = decode(rest, lower: "L", upper: "R", range: 0..<8)
|
||||
let id = row * 8 + column
|
||||
print(s, row, column, id)
|
||||
return id
|
||||
}
|
||||
|
||||
let foundSeats = Set(input.map { decodeSeat($0) })
|
||||
print("max seat id", foundSeats.max() ?? -1)
|
||||
|
||||
let allSeats = Set(0...(7+127*8))
|
||||
let freeSeats = allSeats.subtracting(foundSeats)
|
||||
|
||||
let yours = freeSeats.first(where: { foundSeats.contains($0 + 1) && foundSeats.contains($0 - 1)})
|
||||
print("yours", yours ?? -1)
|
34
2020/day6/main.swift
Normal file
34
2020/day6/main.swift
Normal file
|
@ -0,0 +1,34 @@
|
|||
import Foundation
|
||||
|
||||
var input = loadData(day: 6)
|
||||
|
||||
let scanner = Scanner(string: input)
|
||||
scanner.charactersToBeSkipped = nil
|
||||
|
||||
var count = 0
|
||||
var countB = 0
|
||||
var currentGroup: [Character:Int] = [:]
|
||||
var peopleInGroup = 0
|
||||
|
||||
repeat {
|
||||
guard let answers = scanner.scanUpToString("\n") else { fatalError() }
|
||||
peopleInGroup += 1
|
||||
_ = scanner.scanString("\n")
|
||||
|
||||
for answer in answers {
|
||||
currentGroup[answer, default: 0] += 1
|
||||
}
|
||||
|
||||
if scanner.isAtEnd || scanner.scanString("\n") != nil {
|
||||
count += currentGroup.count
|
||||
|
||||
countB += currentGroup.lazy.filter { $1 == peopleInGroup }.count
|
||||
|
||||
currentGroup.removeAll(keepingCapacity: true)
|
||||
peopleInGroup = 0
|
||||
}
|
||||
|
||||
} while !scanner.isAtEnd
|
||||
|
||||
print("count", count)
|
||||
print("part 2", countB)
|
74
2020/day7/main.swift
Normal file
74
2020/day7/main.swift
Normal file
|
@ -0,0 +1,74 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 7)
|
||||
|
||||
|
||||
let scanner = Scanner(string: input)
|
||||
|
||||
struct Rule {
|
||||
var count: Int
|
||||
var color: String
|
||||
}
|
||||
|
||||
extension Scanner {
|
||||
func scanRule() -> Rule? {
|
||||
guard let count = scanInt(),
|
||||
let color = scanUpToString(count == 1 ? " bag" : " bags"),
|
||||
scanString(count == 1 ? "bag" : "bags") != nil
|
||||
else { return nil }
|
||||
return Rule(count: count, color: color)
|
||||
}
|
||||
|
||||
func scanRuleSet() -> (String, [Rule])? {
|
||||
guard
|
||||
let color = scanUpToString(" bags contain"),
|
||||
scanString("bags contain") != nil else { return nil }
|
||||
if scanString("no other bags.") != nil {
|
||||
return (color, [])
|
||||
}
|
||||
|
||||
var rules: [Rule] = []
|
||||
repeat {
|
||||
guard let rule = scanRule() else { return nil }
|
||||
rules.append(rule)
|
||||
} while scanString(",") != nil
|
||||
|
||||
guard scanString(".") != nil else { return nil }
|
||||
|
||||
return (color, rules)
|
||||
}
|
||||
|
||||
func scanAllRules() -> [String: [Rule]]? {
|
||||
var result: [String: [Rule]] = [:]
|
||||
while !isAtEnd {
|
||||
guard let (color, rules) = scanRuleSet() else { return nil }
|
||||
result[color] = rules
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
guard let rules = scanner.scanAllRules() else { fatalError() }
|
||||
//print(rules)
|
||||
|
||||
func findPath(rules: [String: [Rule]], from: String, to: String) -> Bool {
|
||||
guard let from = rules[from] else { return false }
|
||||
if from.contains(where: { $0.color == to }) {
|
||||
return true
|
||||
}
|
||||
|
||||
return from.contains(where: { findPath(rules: rules, from: $0.color, to: to) })
|
||||
}
|
||||
|
||||
let count = rules.lazy.filter { findPath(rules: rules, from: $0.key, to: "shiny gold") }.count
|
||||
|
||||
print("count", count)
|
||||
|
||||
func bagsInside(rules: [String: [Rule]], color: String) -> Int {
|
||||
guard let from = rules[color] else { return 0 }
|
||||
return from.reduce(0) { accum, bag in
|
||||
accum + bag.count + bag.count * bagsInside(rules: rules, color: bag.color)
|
||||
}
|
||||
}
|
||||
|
||||
print("total bags", bagsInside(rules: rules, color: "shiny gold"))
|
134
2020/day8/main.swift
Normal file
134
2020/day8/main.swift
Normal file
|
@ -0,0 +1,134 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 8)
|
||||
|
||||
let scanner = Scanner(string: input)
|
||||
|
||||
enum Instruction: String {
|
||||
case nop
|
||||
case acc
|
||||
case jmp
|
||||
}
|
||||
|
||||
struct Line {
|
||||
var instruction: Instruction
|
||||
var argument: Int
|
||||
}
|
||||
|
||||
extension Scanner {
|
||||
func instruction() -> Instruction? {
|
||||
guard let string = scanUpToCharacters(from: .whitespaces),
|
||||
let instruction = Instruction(rawValue: string)
|
||||
else { return nil }
|
||||
return instruction
|
||||
}
|
||||
|
||||
func line() -> Line? {
|
||||
guard let ins = instruction(),
|
||||
let argument = scanInt()
|
||||
else { return nil }
|
||||
return Line(instruction: ins, argument: argument)
|
||||
}
|
||||
|
||||
func program() -> [Line]? {
|
||||
var program = [Line]()
|
||||
while !isAtEnd {
|
||||
guard let line = self.line() else { return nil }
|
||||
program.append(line)
|
||||
}
|
||||
return program
|
||||
}
|
||||
}
|
||||
|
||||
class Computer {
|
||||
var program: [Line]
|
||||
var ip: Int = 0
|
||||
var acc: Int = 0
|
||||
|
||||
init(program: [Line]) {
|
||||
self.program = program
|
||||
}
|
||||
|
||||
var visited: Set<Int> = []
|
||||
|
||||
func runLine() {
|
||||
let line = program[ip]
|
||||
switch line.instruction {
|
||||
case .nop:
|
||||
ip += 1
|
||||
|
||||
case .acc:
|
||||
acc += line.argument
|
||||
ip += 1
|
||||
|
||||
case .jmp:
|
||||
ip += line.argument
|
||||
}
|
||||
}
|
||||
|
||||
func run() {
|
||||
ip = 0
|
||||
acc = 0
|
||||
|
||||
while ip < program.count {
|
||||
let (inserted, _) = visited.insert(ip)
|
||||
if !inserted {
|
||||
print("Repeated instruction", acc)
|
||||
return
|
||||
}
|
||||
|
||||
runLine()
|
||||
}
|
||||
print("Finished", acc)
|
||||
}
|
||||
|
||||
func find(ip: Int, acc: Int, changed: Bool, visited: Set<Int>) -> Int?
|
||||
{
|
||||
if ip >= program.count {
|
||||
return acc
|
||||
}
|
||||
|
||||
if (visited.contains(ip)) {
|
||||
return nil
|
||||
}
|
||||
|
||||
let newVisited = visited.union([ip])
|
||||
|
||||
let line = program[ip]
|
||||
switch line.instruction {
|
||||
case .acc:
|
||||
return find(ip: ip + 1, acc: acc + line.argument, changed: changed, visited: newVisited)
|
||||
|
||||
case .nop:
|
||||
if let result = find(ip: ip + 1, acc: acc, changed: changed, visited: newVisited) {
|
||||
return result
|
||||
}
|
||||
|
||||
if !changed, let result = find(ip: ip + line.argument, acc: acc, changed: true, visited: newVisited) {
|
||||
print("Found result by changing nop to jmp at", ip)
|
||||
return result
|
||||
}
|
||||
|
||||
case .jmp:
|
||||
if let result = find(ip: ip + line.argument, acc: acc, changed: changed, visited: newVisited) {
|
||||
return result
|
||||
}
|
||||
|
||||
if !changed, let result = find(ip: ip + 1, acc: acc, changed: true, visited: newVisited) {
|
||||
print("Found result by changing jmp to nop at", ip)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
guard let program = scanner.program() else { fatalError() }
|
||||
let computer = Computer(program: program)
|
||||
computer.run()
|
||||
if let found = computer.find(ip: 0, acc: 0, changed: false, visited: []) {
|
||||
print("found solution", found)
|
||||
}
|
||||
|
||||
|
45
2020/day9/main.swift
Normal file
45
2020/day9/main.swift
Normal file
|
@ -0,0 +1,45 @@
|
|||
import Foundation
|
||||
|
||||
let input = loadData(day: 9)
|
||||
let scanner = Scanner(string: input)
|
||||
|
||||
let numbers = scanner.integers()
|
||||
|
||||
var weakness: Int? = nil
|
||||
outer: for i in 25..<numbers.count {
|
||||
let search = numbers[i]
|
||||
|
||||
for j in (i - 25)..<i {
|
||||
for k in j..<i {
|
||||
if search == numbers[j] + numbers[k] {
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print("first which is not sum", i, search)
|
||||
weakness = search
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
guard let weakness = weakness else { fatalError("No weakness found") }
|
||||
|
||||
outer: for i in 0..<numbers.count {
|
||||
var sum = 0
|
||||
var min = Int.max
|
||||
var max = Int.min
|
||||
for j in (i+1)..<numbers.count {
|
||||
let n = numbers[j]
|
||||
sum += n
|
||||
if n < min { min = n }
|
||||
if n > max { max = n }
|
||||
if sum == weakness {
|
||||
print(min + max)
|
||||
break outer
|
||||
}
|
||||
if sum > weakness {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue