generated from devries/aoc_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
Submodule inputs
updated
from 94f935 to 33eea9