Skip to content

Commit

Permalink
put day 21 on hold, start day 22
Browse files Browse the repository at this point in the history
  • Loading branch information
devries committed Mar 29, 2024
1 parent 8e6be56 commit eb73129
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
1 change: 1 addition & 0 deletions day21p2/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var testInput = `...........
...........`

func TestSolve(t *testing.T) {
t.Skip("Skipping test because I know this remains unsolved")
tests := []struct {
input string
steps int
Expand Down
67 changes: 67 additions & 0 deletions day22p1/solution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package day22p1

import (
"fmt"
"io"
"strconv"
"strings"

"aoc/utils"
)

func Solve(r io.Reader) any {
lines := utils.ReadLines(r)
var bricks []Brick

for _, ln := range lines {
b := parseLine(ln)
bricks = append(bricks, b)
}

for _, b := range bricks {
fmt.Println(b)
}

return 0
}

type Vector struct {
X int
Y int
Z int
}

type Brick struct {
A Vector
B Vector
}

func parseLine(ln string) Brick {
parts := strings.Split(ln, "~")

return Brick{parseVector(parts[0]), parseVector(parts[1])}

}

func parseVector(v string) Vector {
parts := strings.Split(v, ",")

vec := Vector{}

for i, s := range parts {
val, err := strconv.Atoi(s)
if err != nil {
utils.Check(err, "Unable to convert %s into integer", s)
}
switch i {
case 0:
vec.X = val
case 1:
vec.Y = val
case 2:
vec.Z = val
}
}

return vec
}
39 changes: 39 additions & 0 deletions day22p1/solution_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package day22p1

import (
"strings"
"testing"

"aoc/utils"
)

var testInput = `1,0,1~1,2,1
0,0,2~2,0,2
0,2,3~2,2,3
0,0,4~0,2,4
2,0,5~2,2,5
0,1,6~2,1,6
1,1,8~1,1,9`

func TestSolve(t *testing.T) {
tests := []struct {
input string
answer int
}{
{testInput, 5},
}

if testing.Verbose() {
utils.Verbose = true
}

for _, test := range tests {
r := strings.NewReader(test.input)

result := Solve(r).(int)

if result != test.answer {
t.Errorf("Expected %d, got %d", test.answer, result)
}
}
}
2 changes: 1 addition & 1 deletion inputs

0 comments on commit eb73129

Please sign in to comment.