diff --git a/2023/day01_trebuchet.go b/2023/day01_trebuchet.go index 0fde970..e36506b 100644 --- a/2023/day01_trebuchet.go +++ b/2023/day01_trebuchet.go @@ -7,7 +7,7 @@ import ( "strconv" ) -func Part1(input io.Reader) (int, error) { +func D01Part1(input io.Reader) (int, error) { scanner := bufio.NewScanner(input) sum := 0 @@ -38,7 +38,7 @@ func Part1(input io.Reader) (int, error) { return sum, nil } -func Part2(input io.Reader) (int, error) { +func D01Part2(input io.Reader) (int, error) { reg, err := regexp.Compile(`[0-9]|one|two|three|four|five|six|seven|eight|nine`) if err != nil { return 0, err diff --git a/2023/day01_trebuchet_test.go b/2023/day01_trebuchet_test.go index ac79419..fd40014 100644 --- a/2023/day01_trebuchet_test.go +++ b/2023/day01_trebuchet_test.go @@ -1,39 +1,26 @@ package _023 import ( - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "os" "testing" ) -func TestPart1(t *testing.T) { +func TestD01Part1(t *testing.T) { tests := []testCase{ {"inputs/day01_test1", 142}, {"inputs/day01", 53974}, } for _, test := range tests { - t.Run(test.filename, check(test, Part1)) + t.Run(test.filename, check(test, D01Part1)) } } -func TestPart2(t *testing.T) { +func TestD01Part2(t *testing.T) { tests := []testCase{ {"inputs/day01_test2", 281}, {"inputs/day01_test3", 277}, {"inputs/day01", 52840}, } for _, test := range tests { - t.Run(test.filename, check(test, Part2)) - } -} - -func check(test testCase, fn solveFunc) func(t *testing.T) { - return func(t *testing.T) { - file, err := os.Open(test.filename) - require.NoError(t, err) - got, err := fn(file) - require.NoError(t, err) - assert.Equal(t, test.want, got) + t.Run(test.filename, check(test, D01Part2)) } } diff --git a/2023/inputs/dayxx b/2023/inputs/dayxx new file mode 100644 index 0000000..e69de29 diff --git a/2023/inputs/dayxx_test1 b/2023/inputs/dayxx_test1 new file mode 100644 index 0000000..e69de29 diff --git a/2023/inputs/dayxx_test2 b/2023/inputs/dayxx_test2 new file mode 100644 index 0000000..e69de29 diff --git a/2023/new_day b/2023/new_day new file mode 100755 index 0000000..e9649ba --- /dev/null +++ b/2023/new_day @@ -0,0 +1,25 @@ +#!/bin/bash +set -euxo pipefail + +if [[ $# -ne 2 ]]; then + >&2 echo "Usage: $0 " + exit 2 +fi + +filename=day$1_$2 +cp template.go $filename.go +cp template_test.go $filename_test.go +if [ "$(uname -s)" == "Linux" ]; then + sed -e "s/Dxx/day$1/g" -i ./$filename.go + sed -e "s/Dxx/day$1/g" -i ./$filename_test.go + sed -e "s/dayxx/day$1/g" -i ./$filename_test.go +else + sed -e "s/Dxx/day$1/g" -i "" ./$filename.go + sed -e "s/Dxx/day$1/g" -i "" ./$filename_test.go + sed -e "s/dayxx/day$1/g" -i "" ./$filename_test.go +fi +mkdir -p inputs +touch inputs/day$1 +touch inputs/day$1_test1 +touch inputs/day$1_test2 +git add "inputs/day$1*" $filename diff --git a/2023/template.go b/2023/template.go new file mode 100644 index 0000000..f78ed69 --- /dev/null +++ b/2023/template.go @@ -0,0 +1,28 @@ +package _023 + +import ( + "bufio" + "io" +) + +func DxxPart1(input io.Reader) (int, error) { + scanner := bufio.NewScanner(input) + + for scanner.Scan() { + line := scanner.Text() + _ = line + } + + return 0, nil +} + +func DxxPart2(input io.Reader) (int, error) { + scanner := bufio.NewScanner(input) + + for scanner.Scan() { + line := scanner.Text() + _ = line + } + + return 0, nil +} diff --git a/2023/template_test.go b/2023/template_test.go new file mode 100644 index 0000000..892c2af --- /dev/null +++ b/2023/template_test.go @@ -0,0 +1,38 @@ +package _023 + +import ( + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "os" + "testing" +) + +func TestDxxPart1(t *testing.T) { + tests := []testCase{ + {"inputs/dayxx_test1", 0}, + {"inputs/dayxx", 0}, + } + for _, test := range tests { + t.Run(test.filename, check(test, DxxPart1)) + } +} + +func TestDxxPart2(t *testing.T) { + tests := []testCase{ + {"inputs/dayxx_test2", 0}, + {"inputs/dayxx", 0}, + } + for _, test := range tests { + t.Run(test.filename, check(test, DxxPart2)) + } +} + +func check(test testCase, fn solveFunc) func(t *testing.T) { + return func(t *testing.T) { + file, err := os.Open(test.filename) + require.NoError(t, err) + got, err := fn(file) + require.NoError(t, err) + assert.Equal(t, test.want, got) + } +}