diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..eb579cf --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,25 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.23' + + - name: Test + run: go test -v -cover ./src/... diff --git a/day1/go.mod b/day1/go.mod deleted file mode 100644 index 66802e5..0000000 --- a/day1/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/truggeri/adventofcode2024/day1 - -go 1.23.4 diff --git a/day2/go.mod b/day2/go.mod deleted file mode 100644 index fd930f9..0000000 --- a/day2/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/truggeri/adventofcode2024/day2 - -go 1.23.4 diff --git a/day3/go.mod b/day3/go.mod deleted file mode 100644 index 07849ce..0000000 --- a/day3/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/truggeri/adventofcode2024/day3 - -go 1.23.4 diff --git a/day4/go.mod b/day4/go.mod deleted file mode 100644 index 03b7780..0000000 --- a/day4/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/truggeri/adventofcode2024/day4 - -go 1.23.4 diff --git a/day5/go.mod b/day5/go.mod deleted file mode 100644 index 4e70982..0000000 --- a/day5/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/truggeri/adventofcode2024/day5 - -go 1.23.4 diff --git a/day1/README.md b/docs/day1.md similarity index 100% rename from day1/README.md rename to docs/day1.md diff --git a/day2/README.md b/docs/day2.md similarity index 100% rename from day2/README.md rename to docs/day2.md diff --git a/day3/README.md b/docs/day3.md similarity index 100% rename from day3/README.md rename to docs/day3.md diff --git a/day4/README.md b/docs/day4.md similarity index 100% rename from day4/README.md rename to docs/day4.md diff --git a/day5/README.md b/docs/day5.md similarity index 100% rename from day5/README.md rename to docs/day5.md diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..65964f4 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/truggeri/adventofcode2024 + +go 1.23.4 diff --git a/day1/main.go b/src/day1/day1.go similarity index 87% rename from day1/main.go rename to src/day1/day1.go index 502d988..8620e04 100644 --- a/day1/main.go +++ b/src/day1/day1.go @@ -1,7 +1,6 @@ -package main +package day1 import ( - "fmt" "slices" "strconv" "strings" @@ -10,16 +9,6 @@ import ( // This is a bit fragile, but the spec doesn't indicate it will ever change const INPUT_SEPARATOR = " " -func main() { - input := `3 4 -4 3 -2 5 -1 3 -3 9 -3 3` - fmt.Println(solve(parseInput(input))) -} - func Solve(input string) uint { return solve(parseInput(input)) } diff --git a/day1/main_test.go b/src/day1/day1_test.go similarity index 93% rename from day1/main_test.go rename to src/day1/day1_test.go index 7e869ed..70c7799 100644 --- a/day1/main_test.go +++ b/src/day1/day1_test.go @@ -1,4 +1,4 @@ -package main +package day1 import ( "testing" diff --git a/day2/main.go b/src/day2/day2.go similarity index 89% rename from day2/main.go rename to src/day2/day2.go index 3ca419d..ce25050 100644 --- a/day2/main.go +++ b/src/day2/day2.go @@ -1,7 +1,6 @@ -package main +package day2 import ( - "fmt" "slices" "strconv" "strings" @@ -13,17 +12,6 @@ const DELTA_MIN = 1 type level uint type report []level -func main() { - input := `7 6 4 2 1 -1 2 7 8 9 -9 7 6 2 1 -1 3 2 4 5 -8 6 4 4 1 -1 3 6 7 9` - solution := Solve(input) - fmt.Println("Solution:", solution) -} - func Solve(input string) uint { return solve(parseInput(input)) } diff --git a/day2/main_test.go b/src/day2/day2_test.go similarity index 94% rename from day2/main_test.go rename to src/day2/day2_test.go index 1eb8880..58accc0 100644 --- a/day2/main_test.go +++ b/src/day2/day2_test.go @@ -1,4 +1,4 @@ -package main +package day2 import ( "testing" diff --git a/day3/main.go b/src/day3/day3.go similarity index 87% rename from day3/main.go rename to src/day3/day3.go index 7ffc569..28826c4 100644 --- a/day3/main.go +++ b/src/day3/day3.go @@ -1,7 +1,6 @@ -package main +package day3 import ( - "fmt" "regexp" "slices" "strconv" @@ -20,11 +19,6 @@ func (m mul) Eval() uint { return m.x * m.y } -func main() { - input := "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))" - fmt.Println("Solution:", Solve(input)) -} - func Solve(input string) uint { return accumulate(parseInput(input)) } diff --git a/day3/main_test.go b/src/day3/day3_test.go similarity index 94% rename from day3/main_test.go rename to src/day3/day3_test.go index 985662a..1d7513e 100644 --- a/day3/main_test.go +++ b/src/day3/day3_test.go @@ -1,4 +1,4 @@ -package main +package day3 import ( "testing" diff --git a/day4/main.go b/src/day4/day4.go similarity index 93% rename from day4/main.go rename to src/day4/day4.go index acb28b1..53d134d 100644 --- a/day4/main.go +++ b/src/day4/day4.go @@ -1,7 +1,6 @@ -package main +package day4 import ( - "fmt" "slices" "strings" "unicode/utf8" @@ -11,20 +10,6 @@ const WORD_TO_FIND = "XMAS" var _rows []string -func main() { - input := `MMMSXXMASM -MSAMXMSMSA -AMXSXMAAMM -MSAMASMSMX -XMASAMXAMM -XXAMMXXAMA -SMSMSASXSS -SAXAMASAAA -MAMMMXMMMM -MXMXAXMASX` - fmt.Println("Solution:", Solve(input)) -} - func Solve(input string) uint { _rows = make([]string, 0) return matchesByStrategy(input, rows) + matchesByStrategy(input, columns) + matchesByStrategy(input, diagonals) diff --git a/day4/main_test.go b/src/day4/day4_test.go similarity index 99% rename from day4/main_test.go rename to src/day4/day4_test.go index fa8663b..dfa5e09 100644 --- a/day4/main_test.go +++ b/src/day4/day4_test.go @@ -1,4 +1,4 @@ -package main +package day4 import ( "testing" diff --git a/day5/main.go b/src/day5/day5.go similarity index 85% rename from day5/main.go rename to src/day5/day5.go index d4eeb86..b82eb21 100644 --- a/day5/main.go +++ b/src/day5/day5.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "slices" "strconv" "strings" @@ -11,38 +10,6 @@ type pageNumber uint type rule pageNumber type batch []pageNumber -func main() { - input := `47|53 -97|13 -97|61 -97|47 -75|29 -61|13 -75|53 -29|13 -97|29 -53|29 -61|53 -97|53 -61|29 -47|13 -75|47 -97|75 -47|61 -75|61 -47|29 -75|13 -53|13 - -75,47,61,53,29 -97,61,53,29,13 -75,29,13 -75,97,47,61,53 -61,13,29 -97,13,75,29,47` - fmt.Println("Solution:", Solve(input)) -} - func Solve(input string) uint { rules, batches := parseInput(input) var count uint = 0 diff --git a/day5/main_test.go b/src/day5/day5_test.go similarity index 100% rename from day5/main_test.go rename to src/day5/day5_test.go