This commit is contained in:
2023-07-15 10:58:57 -05:00
parent a1b43b389a
commit 1e0d6df700
2 changed files with 37 additions and 1 deletions

21
dayfour.go Normal file
View File

@@ -0,0 +1,21 @@
package main
func incrementIfEncapsulated(pair [2][2]int, solution *int) {
if isEncapsulated(pair[0], pair[1]) {
*solution++
}
}
func isEncapsulated(first [2]int, second [2]int) bool {
return first[0] <= second[0] && first[1] >= second[1] || second[0] <= first[0] && second[1] >= first[1]
}
func dayFour(input [][2][2]int) int {
solution := 0
for _, pair := range input {
incrementIfEncapsulated(pair, &solution)
}
return solution
}

17
main.go
View File

@@ -70,5 +70,20 @@ func main() {
`)
fmt.Println(dayThreeResult)
// printRunes()
/** DAY FOUR */
fmt.Println("\nDAY FOUR")
dayFourInput := [][2][2]int{
{{2, 4}, {6, 8}},
{{2, 3}, {4, 5}},
{{5, 7}, {7, 9}},
{{2, 8}, {3, 7}},
{{6, 6}, {4, 6}},
{{2, 6}, {4, 8}},
}
var dayFourResult = dayFour(dayFourInput)
fmt.Println(dayFourResult)
}