Skip to content

Commit 7a9a7b1

Browse files
Solve day01 part 02 Swift
1 parent 132bd12 commit 7a9a7b1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

2022.playground/Pages/Day01.xcplaygroundpage/Contents.swift

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ func partOne() -> Int {
2222
return highestCalorie[0].caloriesSum
2323
}
2424

25+
func partTwo() -> Int {
26+
let input = load(file: "input01", ofType: .txt)!
27+
var elves = getElves(from: input)
28+
var highestCalorie = elves.sorted { $0.caloriesSum > $1.caloriesSum }
29+
return highestCalorie[0].caloriesSum + highestCalorie[1].caloriesSum + highestCalorie[2].caloriesSum
30+
}
31+
2532
func getElves(from input: String) -> [Elf] {
2633
let elvesCalories = input.split(separator: "\n\n")
2734
var elves: [Elf] = []
@@ -33,5 +40,6 @@ func getElves(from input: String) -> [Elf] {
3340
}
3441

3542
print(partOne())
43+
print(partTwo())
3644

3745
//: [Next](@next)

0 commit comments

Comments
 (0)