mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-05-18 19:13:27 +02:00
updated template script for test args order
This commit is contained in:
+2
-7
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||||
"github.com/alexchao26/advent-of-code-go/util"
|
"github.com/alexchao26/advent-of-code-go/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+2
-7
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||||
"github.com/alexchao26/advent-of-code-go/util"
|
"github.com/alexchao26/advent-of-code-go/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+2
-7
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||||
"github.com/alexchao26/advent-of-code-go/util"
|
"github.com/alexchao26/advent-of-code-go/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+2
-7
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||||
"github.com/alexchao26/advent-of-code-go/util"
|
"github.com/alexchao26/advent-of-code-go/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+2
-7
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||||
"github.com/alexchao26/advent-of-code-go/util"
|
"github.com/alexchao26/advent-of-code-go/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+2
-7
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alexchao26/advent-of-code-go/mathutil"
|
||||||
"github.com/alexchao26/advent-of-code-go/util"
|
"github.com/alexchao26/advent-of-code-go/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -33,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+1
-7
@@ -34,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+1
-7
@@ -34,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+1
-7
@@ -34,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+1
-7
@@ -34,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+1
-7
@@ -34,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
+1
-7
@@ -34,19 +34,13 @@ func part1(input string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func part2(input string) int {
|
func part2(input string) int {
|
||||||
parsed := parseInput(input)
|
|
||||||
_ = parsed
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseInput(input string) []int {
|
func parseInput(input string) (ans []int) {
|
||||||
var ans []int
|
|
||||||
|
|
||||||
lines := strings.Split(input, "\n")
|
lines := strings.Split(input, "\n")
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
ans = append(ans, mathutil.StrToInt(l))
|
ans = append(ans, mathutil.StrToInt(l))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-23
@@ -1,18 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
var tests1 = []struct {
|
func Test_part1(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart1(t *testing.T) {
|
|
||||||
for _, tt := range tests1 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part1(tt.input); got != tt.want {
|
if got := part1(tt.input); got != tt.want {
|
||||||
t.Errorf("part1() = %v, want %v", got, tt.want)
|
t.Errorf("part1() = %v, want %v", got, tt.want)
|
||||||
@@ -21,17 +21,15 @@ func TestPart1(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tests2 = []struct {
|
func Test_part2(t *testing.T) {
|
||||||
name string
|
tests := []struct {
|
||||||
want int
|
name string
|
||||||
input string
|
input string
|
||||||
// add extra args if needed
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
func TestPart2(t *testing.T) {
|
|
||||||
for _, tt := range tests2 {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if got := part2(tt.input); got != tt.want {
|
if got := part2(tt.input); got != tt.want {
|
||||||
t.Errorf("part2() = %v, want %v", got, tt.want)
|
t.Errorf("part2() = %v, want %v", got, tt.want)
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newComputerFromInput(input string) computer {
|
||||||
|
var instructions []instruction
|
||||||
|
|
||||||
|
for _, l := range strings.Split(input, "\n") {
|
||||||
|
inst := instruction{}
|
||||||
|
fmt.Sscanf(l, "%s %d", &inst.operation, &inst.argument)
|
||||||
|
instructions = append(instructions, inst)
|
||||||
|
}
|
||||||
|
|
||||||
|
return computer{instructions: instructions}
|
||||||
|
}
|
||||||
|
|
||||||
|
type computer struct {
|
||||||
|
instructions []instruction
|
||||||
|
index int
|
||||||
|
accumulator int
|
||||||
|
}
|
||||||
|
|
||||||
|
type instruction struct {
|
||||||
|
operation string
|
||||||
|
argument int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *computer) step() {
|
||||||
|
switch inst := c.instructions[c.index]; inst.operation {
|
||||||
|
case "acc":
|
||||||
|
c.accumulator += inst.argument
|
||||||
|
c.index++
|
||||||
|
case "jmp":
|
||||||
|
c.index += inst.argument
|
||||||
|
case "nop":
|
||||||
|
c.index++
|
||||||
|
default:
|
||||||
|
panic("unhandled operation type" + inst.operation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// func isInfiniteLoop(comp computer) (finalAccumulatorVal int, isLoop bool) {
|
||||||
|
// ranInstructionsIndices := map[int]bool{}
|
||||||
|
// for comp.index < len(comp.instructions) {
|
||||||
|
// nextInst := comp.index
|
||||||
|
// // is an infinite loop, return out
|
||||||
|
// if ranInstructionsIndices[nextInst] {
|
||||||
|
// return 0, true
|
||||||
|
// }
|
||||||
|
// ranInstructionsIndices[nextInst] = true
|
||||||
|
|
||||||
|
// comp.step()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // instructions finished, return final accumulator & indicate it was not an
|
||||||
|
// // infinite loop
|
||||||
|
// return comp.accumulator, false
|
||||||
|
// }
|
||||||
@@ -27,7 +27,7 @@ func Test_part1(t *testing.T) {
|
|||||||
input string
|
input string
|
||||||
want int
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@@ -44,7 +44,7 @@ func Test_part2(t *testing.T) {
|
|||||||
input string
|
input string
|
||||||
want int
|
want int
|
||||||
}{
|
}{
|
||||||
// {"actual", ACTUAL_ANSWER, util.ReadFile("input.txt")},
|
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user