This commit is contained in:
Andrew Glaze 2024-08-18 13:14:40 -04:00
commit 84bb9e78e8
13 changed files with 5414 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

2248
Input/day01.txt Normal file

File diff suppressed because it is too large Load Diff

2500
Input/day02.txt Normal file

File diff suppressed because it is too large Load Diff

300
Input/day03.txt Normal file
View File

@ -0,0 +1,300 @@
DsPhSBQQQhqmBDhPDsFwjwsLjlRjlttvjvvtRb
rNJMNNbrHrtjHLHjvwtg
fNbNzZdrZnMnMPnQShFPDmnqFm
QWVCFfQffgQCVZzVVpHsHJBqtpspJFRHqq
mwDbmnnGNlNcwNDDNRbnNDlJTpBJBtJGtPTLsBGqTqqsqp
MlSdnScRnnmmDjSdNSdCzvggWzrgzjvfvrgVzW
gsMljbrjlZlWcWMJrWwTwbmwQbmmLDQQLhwL
CdgpzdgpgnfThHfFRwhfRf
SptgpSpnCNpVSGNPvPGSddcMWjMrjqBsJcWqMcBWcVlZ
JcJLQQFWhQJPJpWcwjHvMQvnnlMvzBHd
tCtGZrmVRmVGTVTtCfRTCHHNNvdNzmdMvMlNzvwdvw
CTGGRftfSGtGTGDLbFchSgSWWWcM
QcMFQrvrQbvtczbVbjbMzZzRpqmDDmqqnNzCDCDC
SHHfPJssGLPSdHThLhHdRmqNmNssnNmNCNnpjmsn
LhLJfTdLJwfgPTdfGccrtjcMrccwvcrrFr
jFLLLqDGjbtqLCChpMMhMBvpwMTmffpZ
ZnJHRncHHgnrsrZffTdMdMBfmMvfvR
NWWPnZrVHrZPCDDQtzDCPLCq
jpFjvBZhDFHZdwcmslcslBLLNl
dVtTVVCzzfrrMPNLLcnVcPLRns
CrzWzTqdWtGCzJtbJCrMjjDFHZQjZSpvFGFgHhHp
JjJqMctnhtDZDQtf
TrFFlrrCCHPwHwlPHFPzDhsffQ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cbgjc
ddQvPnHddnQJHSHSFPdnFfDDTfDMMCrwMlPTwDCsrC
NBnrNHQHBscvhfBM
bbGtgWWWqZFmnZGZbmVCdMzvvShfzfGcdcfMSS
WqbjnmbnjWgmFFgtWVbWZwNTNLjNprNwQLDwrTrHQr
lwwlcjlzQRBcBccbdLCVnNVWJJzfLndd
pZDMtZpSDMZpMZMsPtHVNJVfRCRddVndnJLSJd
mDTZvTqtDDHttRPcqhQlwgGlghbqBh
DTspTqssqTbdmCMwVmnmlfCD
PLPWjjrSjvPzqZvjvRqjLtPwnnHCmWVcncMnnwmncHcHll
RFztFjjqjQFQTbdTbQ
hTFSVSdhMMVMFjjgbthcbzczcg
DvwCJVJWWJDRnfmbDmccfmmgfb
QrJvPGWWnpVMqdZsZpqM
gRLcHbgnfpgpJjlqqp
SFwrTHFBqlZtBPZq
HTzDwmSvCvCmsmmvTSwvFwcfRRNRLcQRWNssNNbRWLWL
PpMgDMDnsWSnjBQnrjbn
LFcVVGChCFdhdVFZVpVCdVbvQbRrbvBBbBjQSJZrrJrR
FNwGNCCFHcVTHcFdHHHTDzMzfsgzwpPWMmPflmtt

24
Package.resolved Normal file
View File

@ -0,0 +1,24 @@
{
"originHash" : "23baadbc515ba47de84bba41a92b072f7e94d25235c8c91b5566b691c2085e3c",
"pins" : [
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax.git",
"state" : {
"revision" : "515f79b522918f83483068d99c68daeb5116342d",
"version" : "600.0.0-prerelease-2024-08-14"
}
},
{
"identity" : "swift-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-testing.git",
"state" : {
"revision" : "c55848b2aa4b29a4df542b235dfdd792a6fbe341",
"version" : "0.12.0"
}
}
],
"version" : 3
}

26
Package.swift Normal file
View File

@ -0,0 +1,26 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "aoc2022",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "aoc2022",
targets: ["aoc2022"]),
],
dependencies: [
.package(url: "https://github.com/swiftlang/swift-testing.git", from: "0.12.0"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "aoc2022"),
.testTarget(
name: "aoc2022Tests",
dependencies: ["aoc2022", .product(name: "Testing", package: "swift-testing")]),
]
)

View File

@ -0,0 +1,5 @@
// The Swift Programming Language
// https://docs.swift.org/swift-book
enum Err: Error {
case NotImplemented
}

View File

@ -0,0 +1,25 @@
struct Day01 {
static func part1(_ input: String) -> Int {
let elves = input
.split(separator: "\n\n")
.map({ elf in
elf.split(separator: "\n")
.map({snack in Int(snack)!})
.reduce(0, +)
})
return elves.max()!
}
static func part2(_ input: String) -> Int {
let elves = input
.split(separator: "\n\n")
.map({ elf in
elf.split(separator: "\n")
.map({snack in Int(snack)!})
.reduce(0, +)
})
.sorted(by: >)
return elves[0..<3].reduce(0,+)
}
}

127
Sources/aoc2022/day02.swift Normal file
View File

@ -0,0 +1,127 @@
struct Day02 {
enum JankenResponse: Character, RawRepresentable {
case rock = "X"
case paper = "Y"
case scissors = "Z"
func getResult(against: JankenPrompt) -> JankenResult {
switch self {
case .rock:
switch against {
case .rock:
return .tie
case .paper:
return .lose
case .scissors:
return .win
}
case .paper:
switch against {
case .rock:
return .win
case .paper:
return .tie
case .scissors:
return .lose
}
case .scissors:
switch against {
case .rock:
return .lose
case .paper:
return .win
case .scissors:
return .tie
}
}
}
func getPointVal() -> Int {
return switch self {
case .rock:
1
case .paper:
2
case .scissors:
3
}
}
}
enum JankenPrompt: Character, RawRepresentable {
case rock = "A"
case paper = "B"
case scissors = "C"
func getResponse(result: JankenResult) -> JankenResponse {
switch self {
case .rock:
switch result {
case .win:
return .paper
case .tie:
return .rock
case .lose:
return .scissors
}
case .paper:
switch result {
case .win:
return .scissors
case .tie:
return .paper
case .lose:
return .rock
}
case .scissors:
switch result {
case .win:
return .rock
case .tie:
return .scissors
case .lose:
return .paper
}
}
}
}
enum JankenResult: Int {
case win = 6
case lose = 0
case tie = 3
init(char: Character) {
switch char {
case "X":
self = .lose
case "Y":
self = .tie
case "Z":
self = .win
default:
fatalError("\(char) is not a valid JankenResult")
}
}
}
static func part1(_ input: String) -> Int {
let roundScores = input.split(separator: "\n")
.map({ round in
let prompt = JankenPrompt(rawValue: round.first!)!
let response = JankenResponse(rawValue: round.last!)!
return response.getResult(against: prompt).rawValue + response.getPointVal()
})
return roundScores.reduce(0, +)
}
static func part2(_ input: String) -> Int {
let roundScores = input.split(separator: "\n")
.map({ round in
let prompt = JankenPrompt(rawValue: round.first!)!
let result = JankenResult(char: round.last!)
return prompt.getResponse(result: result).getPointVal() + result.rawValue
})
return roundScores.reduce(0, +)
}
}

View File

@ -0,0 +1,26 @@
struct Day03 {
static func part1(_ input: String) -> Int {
let itemPriority = input.split(separator: "\n")
.map({ sack in
let start = sack.startIndex
let end = sack.endIndex
let mid = ((end - start) / 2) + start
return sack[start..<mid].filter(sack[mid..<end].contains).first!
})
.map(charToPriority)
return itemPriority.reduce(0, +)
}
static func charToPriority(_ char: Character) -> Int {
let ascii = Int(char.asciiValue!)
switch ascii {
case 97...122:
return ascii - 96
case 65...90:
return ascii - (64 - 26)
default:
fatalError("\(char) is not a valid character!")
}
}
}

View File

@ -0,0 +1,66 @@
import Testing
@testable import aoc2022
@Suite("Day 1 Tests") struct Day01Tests {
@Test("Part 1 Test") func testPart1() {
let input = """
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
"""
let out = Day01.part1(input)
#expect(24000 == out, "\(out) should be 24000")
}
@Test("Part 1 Actual") func runPart1() throws {
let input = try String(contentsOfFile: "Input/day01.txt", encoding: .utf8)
let out = Day01.part1(input)
#expect(67016 == out, "\(out) should be 67016")
}
@Test("Part 2 Test") func testPart2() {
let input = """
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
"""
let out = Day01.part2(input)
#expect(45000 == out, "\(out) should be 45000")
}
@Test("Part 2 Actual") func runPart2() throws {
let input = try String(contentsOfFile: "Input/day01.txt", encoding: .utf8)
let out = Day01.part2(input)
#expect(200116 == out, "\(out) should be 200116")
}
}

View File

@ -0,0 +1,36 @@
import Testing
@testable import aoc2022
@Suite("Day 2") struct Day02Test {
@Test("Part 1 Test") func testPart1() {
let input = """
A Y
B X
C Z
"""
let out = Day02.part1(input)
#expect(out == 15)
}
@Test("Part 1 actual") func runPart1() throws {
let input = try String(contentsOfFile: "Input/day02.txt")
let out = Day02.part1(input)
#expect(out == 12740)
}
@Test("Part 2 Test") func testPart2() {
let input = """
A Y
B X
C Z
"""
let out = Day02.part2(input)
#expect(out == 12)
}
@Test("Part 2 actual") func runPart2() throws {
let input = try String(contentsOfFile: "Input/day02.txt")
let out = Day02.part2(input)
#expect(out == 11980)
}
}

View File

@ -0,0 +1,23 @@
import Testing
@testable import aoc2022
@Suite("Day 3 Tests") struct Day03Test {
@Test("Part 1 Test") func testPart1() {
let input = """
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
"""
let out = Day03.part1(input)
#expect(out == 157)
}
@Test("Part 1 Actual") func runPart1() throws {
let input = try String(contentsOfFile: "Input/day03.txt")
let out = Day03.part1(input)
#expect(out == 8176)
}
}