Skip to content

Commit 536c03c

Browse files
committed
Some cleanup
1 parent 0bd5f79 commit 536c03c

File tree

9 files changed

+195
-19
lines changed

9 files changed

+195
-19
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v4
10+
1011
- name: Setup Go
1112
uses: actions/setup-go@v4
12-
with:
13-
go-version: '1.21.3'
13+
1414
- name: Run test
1515
run: make testall
File renamed without changes.

days/23-1/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/robryanx/adventofcode2023/util"
7+
)
8+
9+
func main() {
10+
rows, err := util.ReadStrings(23, true, "\n")
11+
if err != nil {
12+
panic(err)
13+
}
14+
15+
fmt.Println(rows)
16+
}

days_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ func TestDays(t *testing.T) {
5757
day := day
5858
t.Run(day, func(t *testing.T) {
5959
t.Parallel()
60-
cmd := exec.Command(fmt.Sprintf("bin/%s", day))
61-
out, err := cmd.CombinedOutput()
60+
runCmd := exec.Command("go", "run", fmt.Sprintf("days/%s/main.go", day))
61+
output, err := runCmd.CombinedOutput()
62+
if err != nil {
63+
fmt.Println(output)
64+
}
6265

6366
assert.NoError(t, err)
64-
assert.Equal(t, expect, strings.TrimRight(string(out), "\n"), fmt.Sprintf("Day %s", day))
67+
assert.Equal(t, expect, strings.TrimRight(string(output), "\n"), fmt.Sprintf("Day %s", day))
6568
})
6669
}
6770
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/robryanx/adventofcode2023
22

3-
go 1.21.1
3+
go 1.23
44

55
require (
66
github.com/stretchr/testify v1.8.4

inputs/23.txt

Lines changed: 141 additions & 0 deletions
Large diffs are not rendered by default.

samples/23.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#.#####################
2+
#.......#########...###
3+
#######.#########.#.###
4+
###.....#.>.>.###.#.###
5+
###v#####.#v#.###.#.###
6+
###.>...#.#.#.....#...#
7+
###v###.#.#.#########.#
8+
###...#.#.#.......#...#
9+
#####.#.#.#######.#.###
10+
#.....#.#.#.......#...#
11+
#.#####.#.#.#########v#
12+
#.#...#...#...###...>.#
13+
#.#.#v#######v###.###v#
14+
#...#.>.#...>.>.#.###.#
15+
#####v#.#.###v#.#.###.#
16+
#.....#...#...#.#.#...#
17+
#.#########.###.#.#.###
18+
#...###...#...#...#.###
19+
###.###.#.###v#####v###
20+
#...#...#.#.>.>.#.>.###
21+
#.###.###.#.###.#.#v###
22+
#.....###...###...#...#
23+
#####################.#

util/astar.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package util
22

33
import (
44
"container/heap"
5-
"fmt"
65
)
76

87
type priorityQueue []*node
@@ -287,12 +286,6 @@ func Pathfind(grid [][]byte, from NodePos, to NodePos) (path []NodePos, distance
287286
current.open = false
288287
current.closed = true
289288

290-
if current.pos.Y == 0 && current.pos.X == 2 {
291-
fmt.Printf("%+v\n", current)
292-
fmt.Println(current.parentDirection())
293-
fmt.Println(current.neighbors(grid))
294-
}
295-
296289
if current == nm.get(to) {
297290
// Found a path to the goal.
298291
p := []NodePos{}
@@ -310,11 +303,6 @@ func Pathfind(grid [][]byte, from NodePos, to NodePos) (path []NodePos, distance
310303
cost := current.pos.cost + neighbor.cost
311304
neighborNode := nm.get(neighbor)
312305

313-
if current.pos.Y == 0 && current.pos.X == 2 {
314-
fmt.Printf("%+v\n", neighborNode)
315-
fmt.Println(cost)
316-
}
317-
318306
if cost <= neighborNode.pos.cost {
319307
if neighborNode.open {
320308
heap.Remove(nq, neighborNode.index)

util/readinput.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package util
33
import (
44
"fmt"
55
"os"
6+
"path/filepath"
7+
"runtime"
68
"strconv"
79
"strings"
810
)
@@ -15,7 +17,10 @@ func filename(day int, isSample bool) string {
1517
folder = "samples"
1618
}
1719

18-
return fmt.Sprintf("%s/%d.txt", folder, day)
20+
_, fileName, _, _ := runtime.Caller(0)
21+
prefixPath := filepath.Dir(fileName)
22+
23+
return fmt.Sprintf("%s/../%s/%d.txt", prefixPath, folder, day)
1924
}
2025

2126
func ReadStrings(day int, isSample bool, delim string) ([]string, error) {

0 commit comments

Comments
 (0)