Commit 4930d90 1 parent 37c35f6 commit 4930d90 Copy full SHA for 4930d90
File tree 4 files changed +23
-107
lines changed
4 files changed +23
-107
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,9 @@ package euler2
2
2
3
3
import (
4
4
"encoding/csv"
5
+ "os"
5
6
"sort"
6
7
"sync"
7
-
8
- "github.com/andrew-field/projecteuler-go/filefunctions"
9
8
)
10
9
11
10
var (
@@ -42,13 +41,18 @@ var (
42
41
43
42
// nameScores returns the summation of all the name scores in the file p022_names.txt
44
43
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 ()
47
49
48
50
// Read names and sort.
49
51
reader := csv .NewReader (f )
50
52
records , err := reader .ReadAll ()
51
- filefunctions .Check (err )
53
+ if err != nil {
54
+ panic (err )
55
+ }
52
56
names := records [0 ]
53
57
sort .Strings (names ) // Score depends on position in list.
54
58
Original file line number Diff line number Diff line change @@ -3,17 +3,20 @@ package euler4
3
3
import (
4
4
"bufio"
5
5
"io"
6
+ "os"
6
7
"strconv"
7
8
8
9
"github.com/andrew-field/maths"
9
- "github.com/andrew-field/projecteuler-go/filefunctions"
10
10
)
11
11
12
12
// maximumPathSumTwo returns the maximum total from top to bottom of a pyramid by starting at the top of the triangle
13
13
// and moving to adjacent numbers on the row below.
14
14
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 ()
17
20
18
21
reader := bufio .NewReader (f ) // This reader is used because of its efficiency with many small reads.
19
22
@@ -26,9 +29,15 @@ func maximumPathSumTwo() int {
26
29
if err == io .EOF {
27
30
break
28
31
}
29
- filefunctions .Check (err )
32
+ if err != nil {
33
+ panic (err )
34
+ }
35
+
30
36
value , err := strconv .Atoi (string (number ))
31
- filefunctions .Check (err )
37
+ if err != nil {
38
+ panic (err )
39
+ }
40
+
32
41
numbers = append (numbers , value )
33
42
}
34
43
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments