Skip to content

Commit 3b2621e

Browse files
committed
day4
1 parent d2f4e8a commit 3b2621e

File tree

4 files changed

+137
-2
lines changed

4 files changed

+137
-2
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1230"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "Day4"
18+
BuildableName = "Day4"
19+
BlueprintName = "Day4"
20+
ReferencedContainer = "container:">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "Day4"
48+
BuildableName = "Day4"
49+
BlueprintName = "Day4"
50+
ReferencedContainer = "container:">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "Day4"
65+
BuildableName = "Day4"
66+
BlueprintName = "Day4"
67+
ReferencedContainer = "container:">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

Example Inputs/day4-Example.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
2+
byr:1937 iyr:2017 cid:147 hgt:183cm
3+
4+
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
5+
hcl:#cfa07d byr:1929
6+
7+
hcl:#ae17e1 iyr:2013
8+
eyr:2024
9+
ecl:brn pid:760753108 byr:1931
10+
hgt:179cm
11+
12+
hcl:#cfa07d eyr:2025 pid:166559648
13+
iyr:2011 ecl:brn hgt:59in

Sources/Day4/README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
1-
# [Day 4 - ](https://adventofcode.com/2020/day/3)
1+
# [Day 4 - Passport Processing](https://adventofcode.com/2020/day/3)
22

33
## Part One
4+
You arrive at the airport only to realize that you grabbed your North Pole Credentials instead of your passport. While these documents are extremely similar, North Pole Credentials aren't issued by a country and therefore aren't actually valid documentation for travel in most of the world.
5+
6+
It seems like you're not the only one having problems, though; a very long line has formed for the automatic passport scanners, and the delay could upset your travel itinerary.
7+
8+
Due to some questionable network security, you realize you might be able to solve both of these problems at the same time.
9+
10+
The automatic passport scanners are slow because they're having trouble detecting which passports have all required fields. The expected fields are as follows:
11+
12+
- byr (Birth Year)
13+
- iyr (Issue Year)
14+
- eyr (Expiration Year)
15+
- hgt (Height)
16+
- hcl (Hair Color)
17+
- ecl (Eye Color)
18+
- pid (Passport ID)
19+
- cid (Country ID)
20+
Passport data is validated in batch files (your puzzle input). Each passport is represented as a sequence of key:value pairs separated by spaces or newlines. Passports are separated by blank lines.
21+
22+
Here is an example batch file containing four passports:
23+
24+
```
25+
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
26+
byr:1937 iyr:2017 cid:147 hgt:183cm
27+
28+
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
29+
hcl:#cfa07d byr:1929
30+
31+
hcl:#ae17e1 iyr:2013
32+
eyr:2024
33+
ecl:brn pid:760753108 byr:1931
34+
hgt:179cm
35+
36+
hcl:#cfa07d eyr:2025 pid:166559648
37+
iyr:2011 ecl:brn hgt:59in
38+
```
39+
The first passport is valid - all eight fields are present. The second passport is invalid - it is missing hgt (the Height field).
40+
41+
The third passport is interesting; the only missing field is cid, so it looks like data from North Pole Credentials, not a passport at all! Surely, nobody would mind if you made the system temporarily ignore missing cid fields. Treat this "passport" as valid.
42+
43+
The fourth passport is missing two fields, cid and byr. Missing cid is fine, but missing any other field is not, so this passport is invalid.
44+
45+
According to the above rules, your improved system would report 2 valid passports.
46+
47+
Count the number of valid passports - those that have all required fields. Treat cid as optional. In your batch file, how many passports are valid?
448

549

650
## Part Two

Sources/Day4/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct Day4: ParsableCommand {
2424
guard let url = Bundle.module.url(forResource: "input", withExtension: "txt") else { fatalError("File not found")}
2525
input = getInputArray(from: url)
2626
}
27-
27+
print(input)
2828
let solution = ""
2929

3030
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime

0 commit comments

Comments
 (0)