mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-07 20:53:30 +02:00
day13 cleanup
This commit is contained in:
+9
-34
@@ -28,18 +28,12 @@ func main() {
|
||||
flag.Parse()
|
||||
fmt.Println("Running part", part)
|
||||
|
||||
if part == 1 {
|
||||
ans := part1(input)
|
||||
ans := transparentOrigamiDay13(input, part)
|
||||
util.CopyToClipboard(fmt.Sprintf("%v", ans))
|
||||
fmt.Println("Output:", ans)
|
||||
} else {
|
||||
ans := part2(input)
|
||||
util.CopyToClipboard(fmt.Sprintf("%v", ans))
|
||||
fmt.Println("Output:", ans)
|
||||
}
|
||||
}
|
||||
|
||||
func part1(input string) int {
|
||||
func transparentOrigamiDay13(input string, part int) int {
|
||||
parts := strings.Split(input, "\n\n")
|
||||
|
||||
coords := map[[2]int]bool{}
|
||||
@@ -48,19 +42,6 @@ func part1(input string) int {
|
||||
sp := strings.Split(line, ",")
|
||||
coords[[2]int{cast.ToInt(sp[0]), cast.ToInt(sp[1])}] = true
|
||||
}
|
||||
fmt.Println(len(coords))
|
||||
|
||||
// // printing is a pita
|
||||
// grid := make([][]int, 15)
|
||||
// for i := range grid {
|
||||
// grid[i] = make([]int, 15)
|
||||
// }
|
||||
// for c := range coords {
|
||||
// grid[c[1]][c[0]] = 1
|
||||
// }
|
||||
// for _, row := range grid {
|
||||
// fmt.Println(row)
|
||||
// }
|
||||
|
||||
for _, fold := range strings.Split(parts[1], "\n") {
|
||||
cap := regexp.MustCompile(`fold along (x|y)=(\d+)`).FindStringSubmatch(fold)
|
||||
@@ -70,9 +51,6 @@ func part1(input string) int {
|
||||
dir := cap[0]
|
||||
foldCoord := cast.ToInt(cap[1])
|
||||
|
||||
fmt.Println("folding on", dir, foldCoord)
|
||||
|
||||
// fmt.Println(fold, dir, line)
|
||||
// dots will never appear exactly on a fold line
|
||||
isFoldOnX := dir == "x"
|
||||
nextMap := map[[2]int]bool{}
|
||||
@@ -83,7 +61,6 @@ func part1(input string) int {
|
||||
foldCoord - (c[0] - foldCoord),
|
||||
c[1],
|
||||
}
|
||||
fmt.Println(c, "to", folded)
|
||||
nextMap[folded] = true
|
||||
} else {
|
||||
nextMap[c] = true
|
||||
@@ -97,7 +74,6 @@ func part1(input string) int {
|
||||
c[0],
|
||||
foldCoord - (c[1] - foldCoord),
|
||||
}
|
||||
fmt.Println(c, "to", folded)
|
||||
nextMap[folded] = true
|
||||
} else {
|
||||
nextMap[c] = true
|
||||
@@ -107,11 +83,14 @@ func part1(input string) int {
|
||||
|
||||
coords = nextMap
|
||||
|
||||
// TODO just break for part 1
|
||||
// break
|
||||
// return after one fold for part 1?
|
||||
if part == 1 {
|
||||
return len(coords)
|
||||
}
|
||||
}
|
||||
|
||||
// printing is a pita
|
||||
// printing is a pita but necessary for reading part2
|
||||
if part == 2 {
|
||||
max := 0
|
||||
for c := range coords {
|
||||
if c[0] > max {
|
||||
@@ -140,10 +119,6 @@ func part1(input string) int {
|
||||
}
|
||||
fmt.Println(str)
|
||||
}
|
||||
|
||||
return len(coords)
|
||||
}
|
||||
|
||||
func part2(input string) int {
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
+11
-33
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -26,53 +27,30 @@ var example = `6,10
|
||||
fold along y=7
|
||||
fold along x=5`
|
||||
|
||||
func Test_part1(t *testing.T) {
|
||||
func Test_transparentOrigamiDay13(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
part int
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "example",
|
||||
input: example,
|
||||
part: 1,
|
||||
want: 17,
|
||||
},
|
||||
// {
|
||||
// name: "actual",
|
||||
// input: input,
|
||||
// want: 0,
|
||||
// },
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := part1(tt.input); got != tt.want {
|
||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_part2(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "example",
|
||||
input: example,
|
||||
want: 0,
|
||||
name: "actual",
|
||||
part: 1,
|
||||
input: input,
|
||||
want: 731,
|
||||
},
|
||||
// {
|
||||
// name: "actual",
|
||||
// input: input,
|
||||
// want: 0,
|
||||
// },
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := part2(tt.input); got != tt.want {
|
||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||
t.Run(fmt.Sprintf("%s part%d", tt.name, tt.part), func(t *testing.T) {
|
||||
if got := transparentOrigamiDay13(tt.input, tt.part); got != tt.want {
|
||||
t.Errorf("transparentOrigamiDay13() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user