-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: preparing for advent of code 2024
- Loading branch information
Showing
10 changed files
with
183 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
npm-debug.log | ||
node_modules | ||
rust/**/target | ||
|
||
input.txt |
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,10 @@ | ||
PADDED_DAY = $(shell printf "%02d" $(DAY)) | ||
|
||
create-day: | ||
@cp -r ./template puzzles/day$(PADDED_DAY) | ||
|
||
test: | ||
@go test ./puzzles/day$(PADDED_DAY) | ||
|
||
run: | ||
@go run ./puzzles/day$(PADDED_DAY)/main.go |
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,12 @@ | ||
# Advent of Code 2024 | ||
|
||
I've been enjoying Go this year and thought I might learn more by doing AoC in it this year! | ||
|
||
## Advent of Code 2024 Story | ||
|
||
TBD | ||
|
||
## Days | ||
|
||
| Day | #1 | #1 Answer | #2 | #2 Answer | | ||
| --- | --- | --------: | --- | --------: | |
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,11 @@ | ||
module github.com/believer/aoc-2024 | ||
|
||
go 1.23.3 | ||
|
||
require github.com/stretchr/testify v1.10.0 | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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,10 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | ||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,18 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println("Part 1: ", part1("input.txt")) | ||
fmt.Println("Part 2: ", part2("input.txt")) | ||
} | ||
|
||
func part1(name string) int { | ||
return 0 | ||
} | ||
|
||
func part2(name string) int { | ||
return 0 | ||
} |
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,23 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPart1(t *testing.T) { | ||
t.Run("Part 1", func(t *testing.T) { | ||
expected := 0 | ||
actual := part1("test-input.txt") | ||
assert.Equal(t, expected, actual) | ||
}) | ||
} | ||
|
||
func TestPart2(t *testing.T) { | ||
t.Run("Part 2", func(t *testing.T) { | ||
expected := 0 | ||
actual := part2("test-input.txt") | ||
assert.Equal(t, expected, actual) | ||
}) | ||
} |
Empty file.
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,97 @@ | ||
package files | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"path" | ||
"runtime" | ||
) | ||
|
||
// Borrowed from https://github.com/kylehoehns/aoc-2023-go/blob/main/pkg/files/filereader.go | ||
// Seems like a great starting point for me to learn and adjust according to my needs. | ||
|
||
// ReadLines reads a file and returns a slice of strings, one for each line | ||
func ReadLines(name string) []string { | ||
_, callingFile, _, ok := runtime.Caller(1) | ||
|
||
if !ok { | ||
panic("unable to find caller so cannot build path to read file") | ||
} | ||
|
||
return readLines(name, callingFile) | ||
} | ||
|
||
// Read reads a file and returns a string containing the entire file | ||
func Read(name string) string { | ||
_, callingFile, _, ok := runtime.Caller(1) | ||
|
||
if !ok { | ||
panic("unable to find caller so cannot build path to read file") | ||
} | ||
|
||
b, err := os.ReadFile(path.Join(path.Dir(callingFile), name)) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return string(b) | ||
} | ||
|
||
// ReadParagraphs reads a file and returns a slice of slices of strings, one for each line | ||
// A gap of one or more blank lines is used to split the file into groups | ||
func ReadParagraphs(name string) [][]string { | ||
_, callingFile, _, ok := runtime.Caller(1) | ||
|
||
if !ok { | ||
panic("unable to find caller so cannot build path to read file") | ||
} | ||
|
||
lines := readLines(name, callingFile) | ||
|
||
var groups [][]string | ||
|
||
curGroup := make([]string, 0) | ||
|
||
for _, line := range lines { | ||
if line == "" { | ||
groups = append(groups, curGroup) | ||
curGroup = make([]string, 0) | ||
} else { | ||
curGroup = append(curGroup, line) | ||
} | ||
} | ||
|
||
if len(curGroup) > 0 { | ||
groups = append(groups, curGroup) | ||
} | ||
|
||
return groups | ||
} | ||
|
||
func readLines(name string, callingFile string) []string { | ||
inputFile, err := os.Open(path.Join(path.Dir(callingFile), name)) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defer func(inputFile *os.File) { | ||
err := inputFile.Close() | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
}(inputFile) | ||
|
||
scanner := bufio.NewScanner(inputFile) | ||
scanner.Split(bufio.ScanLines) | ||
|
||
var lines []string | ||
|
||
for scanner.Scan() { | ||
lines = append(lines, scanner.Text()) | ||
} | ||
|
||
return lines | ||
} |