day four
This commit is contained in:
21
dayfour.go
Normal file
21
dayfour.go
Normal 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
17
main.go
@@ -70,5 +70,20 @@ func main() {
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
fmt.Println(dayThreeResult)
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user