Compare commits
4 Commits
5dab84eeb3
...
cdbc3f3b16
| Author | SHA1 | Date | |
|---|---|---|---|
| cdbc3f3b16 | |||
| ed445a8be7 | |||
| 8bbf6662b1 | |||
| b60c971d50 |
40
internal/2016/DayThree/code.go
Normal file
40
internal/2016/DayThree/code.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package daythree
|
||||||
|
|
||||||
|
import (
|
||||||
|
"advent-of-code/internal/registry"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
registry.Register("2016D3", ParseInput, PartOne, PartTwo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseInput(filepath string) [][3]int {
|
||||||
|
content, _ := os.ReadFile(filepath)
|
||||||
|
lines := strings.Split(string(content), "\n")
|
||||||
|
var result [][3]int
|
||||||
|
for _, line := range lines {
|
||||||
|
var a, b, c int
|
||||||
|
fmt.Sscanf(line, "%d %d %d", &a, &b, &c)
|
||||||
|
result = append(result, [3]int{a, b, c})
|
||||||
|
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func PartOne(data [][3]int) int {
|
||||||
|
count := 0
|
||||||
|
for _, triangle := range data {
|
||||||
|
a, b, c := triangle[0], triangle[1], triangle[2]
|
||||||
|
if a+b > c && a+c > b && b+c > a {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
func PartTwo(data [][3]int) int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
28
internal/2016/DayThree/code_test.go
Normal file
28
internal/2016/DayThree/code_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package daythree
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestPartOne(t *testing.T) {
|
||||||
|
input := [][3]int{{5, 10, 25}}
|
||||||
|
expected := 0
|
||||||
|
got := PartOne(input)
|
||||||
|
if got != expected {
|
||||||
|
t.Errorf("PartOne() = %d, want %d", got, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPartTwo(t *testing.T) {
|
||||||
|
input := [][3]int{
|
||||||
|
{101, 301, 501},
|
||||||
|
{102, 302, 502},
|
||||||
|
{103, 303, 503},
|
||||||
|
{201, 401, 601},
|
||||||
|
{202, 402, 602},
|
||||||
|
{203, 403, 603},
|
||||||
|
}
|
||||||
|
expected := 6
|
||||||
|
got := PartTwo(input)
|
||||||
|
if got != expected {
|
||||||
|
t.Errorf("PartTwo() = %d, want %d", got, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,5 +2,6 @@ package year2016
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "advent-of-code/internal/2016/DayOne"
|
_ "advent-of-code/internal/2016/DayOne"
|
||||||
|
_ "advent-of-code/internal/2016/DayThree"
|
||||||
_ "advent-of-code/internal/2016/DayTwo"
|
_ "advent-of-code/internal/2016/DayTwo"
|
||||||
)
|
)
|
||||||
|
|||||||
1599
internal/data/2016/DayThree/input.txt
Normal file
1599
internal/data/2016/DayThree/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user