Skip to content

Commit 4930d90

Browse files
committed
fix: remove separate file functions
1 parent 37c35f6 commit 4930d90

File tree

4 files changed

+23
-107
lines changed

4 files changed

+23
-107
lines changed

21-40/22_name_scores.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package euler2
22

33
import (
44
"encoding/csv"
5+
"os"
56
"sort"
67
"sync"
7-
8-
"github.com/andrew-field/projecteuler-go/filefunctions"
98
)
109

1110
var (
@@ -42,13 +41,18 @@ var (
4241

4342
// nameScores returns the summation of all the name scores in the file p022_names.txt
4443
func nameScores() int {
45-
f := filefunctions.OpenFile("p022_names.txt")
46-
defer filefunctions.CloseFile(f)
44+
f, err := os.Open("p022_names.txt")
45+
if err != nil {
46+
panic(err)
47+
}
48+
defer f.Close()
4749

4850
// Read names and sort.
4951
reader := csv.NewReader(f)
5052
records, err := reader.ReadAll()
51-
filefunctions.Check(err)
53+
if err != nil {
54+
panic(err)
55+
}
5256
names := records[0]
5357
sort.Strings(names) // Score depends on position in list.
5458

61-80/67_maximum_path_sum_two.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ package euler4
33
import (
44
"bufio"
55
"io"
6+
"os"
67
"strconv"
78

89
"github.com/andrew-field/maths"
9-
"github.com/andrew-field/projecteuler-go/filefunctions"
1010
)
1111

1212
// maximumPathSumTwo returns the maximum total from top to bottom of a pyramid by starting at the top of the triangle
1313
// and moving to adjacent numbers on the row below.
1414
func maximumPathSumTwo() int {
15-
f := filefunctions.OpenFile("p067_triangle.txt")
16-
defer filefunctions.CloseFile(f)
15+
f, err := os.Open("p067_triangle.txt")
16+
if err != nil {
17+
panic(err)
18+
}
19+
defer f.Close()
1720

1821
reader := bufio.NewReader(f) // This reader is used because of its efficiency with many small reads.
1922

@@ -26,9 +29,15 @@ func maximumPathSumTwo() int {
2629
if err == io.EOF {
2730
break
2831
}
29-
filefunctions.Check(err)
32+
if err != nil {
33+
panic(err)
34+
}
35+
3036
value, err := strconv.Atoi(string(number))
31-
filefunctions.Check(err)
37+
if err != nil {
38+
panic(err)
39+
}
40+
3241
numbers = append(numbers, value)
3342
}
3443

filefunctions/file_functions.go

-25
This file was deleted.

filefunctions/file_functions_test.go

-72
This file was deleted.

0 commit comments

Comments
 (0)