Skip to content

Commit

Permalink
better naming for reading file into paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehoehns committed Nov 28, 2023
1 parent 77cca00 commit 8a250c0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/files/filereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func Read(name string) string {
return string(b)
}

// ReadLinesWithGaps reads a file and returns a slice of slices of strings, one for each line
// 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 ReadLinesWithGaps(name string) [][]string {
func ReadParagraphs(name string) [][]string {
_, callingFile, _, ok := runtime.Caller(1)
if !ok {
panic("unable to find caller so cannot build path to read file")
Expand Down
2 changes: 1 addition & 1 deletion pkg/files/filereader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestReadLinesWithGaps(t *testing.T) {
{"test", "file"},
{"end"},
}
actual := ReadLinesWithGaps("./input-with-gaps.txt")
actual := ReadParagraphs("./input-with-gaps.txt")

assert.Equal(t, expected, actual)
})
Expand Down
9 changes: 4 additions & 5 deletions puzzles/day00/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ func sumOfCaloriesCarriedByTopThreeElves(name string) int {

func elvesFromFile(name string) []elf {
elves := make([]elf, 0)
groups := files.ReadLinesWithGaps(name)
for _, group := range groups {
elf := elf{
paragraphs := files.ReadParagraphs(name)
for _, group := range paragraphs {
elves = append(elves, elf{
totalCalories: ints.ToStringAndSum(group),
}
elves = append(elves, elf)
})
}
return elves
}

0 comments on commit 8a250c0

Please sign in to comment.