diff --git a/dayfour.go b/dayfour.go new file mode 100644 index 0000000..4f14a9d --- /dev/null +++ b/dayfour.go @@ -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 +} diff --git a/main.go b/main.go index ee95aa8..9cae855 100644 --- a/main.go +++ b/main.go @@ -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) }