Skip to content

Commit

Permalink
minor tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
gereons committed Dec 2, 2023
1 parent 77c36c5 commit 71b4a0a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Sources/Day02/Day02.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ struct Game {
var power: Int {
max(red, 1) * max(green, 1) * max(blue, 1)
}

var isPossible: Bool {
red <= 12 && green <= 13 && blue <= 14
}
}

init(_ str: String) {
Expand All @@ -43,19 +47,15 @@ struct Game {
}

var isPossible: Bool {
sets.allSatisfy {
$0.red <= 12 && $0.green <= 13 && $0.blue <= 14
}
sets.allSatisfy { $0.isPossible }
}

var minimumSet: Set {
var red = 0, green = 0, blue = 0
sets.forEach {
red = max(red, $0.red)
green = max(green, $0.green)
blue = max(blue, $0.blue)
}
return Set(red: red, green: green, blue: blue)
Set(
red: sets.max(of: \.red) ?? 0,
green: sets.max(of: \.green) ?? 0,
blue: sets.max(of: \.blue) ?? 0
)
}
}

Expand Down

0 comments on commit 71b4a0a

Please sign in to comment.