File tree 4 files changed +27
-19
lines changed
4 files changed +27
-19
lines changed Original file line number Diff line number Diff line change
1
+ module adventofcode2021
2
+
3
+ go 1.16
File renamed without changes.
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- "bufio "
4
+ "adventofcode2021/src/utils "
5
5
"fmt"
6
- "log"
7
- "os"
8
6
"strconv"
9
7
)
10
8
11
9
func main () {
12
- var lines = readFile ()
10
+ var lines = utils . ReadLines ()
13
11
var depths []int
14
12
for _ , value := range lines {
15
13
if n , err := strconv .Atoi (value ); err == nil {
@@ -43,18 +41,3 @@ func calcIncreases() func(int) int {
43
41
return cnt
44
42
}
45
43
}
46
-
47
- func readFile () []string {
48
- file , err := os .Open ("data" )
49
- if err != nil {
50
- log .Fatalf ("failed opening file: %s" , err )
51
- }
52
- scanner := bufio .NewScanner (file )
53
- scanner .Split (bufio .ScanLines )
54
- var txtlines []string
55
- for scanner .Scan () {
56
- txtlines = append (txtlines , scanner .Text ())
57
- }
58
- file .Close ()
59
- return txtlines
60
- }
Original file line number Diff line number Diff line change
1
+ package utils
2
+
3
+ import (
4
+ "bufio"
5
+ "log"
6
+ "os"
7
+ )
8
+
9
+ func ReadLines () []string {
10
+ file , err := os .Open ("data" )
11
+ if err != nil {
12
+ log .Fatalf ("failed opening file: %s" , err )
13
+ }
14
+ scanner := bufio .NewScanner (file )
15
+ scanner .Split (bufio .ScanLines )
16
+ var txtlines []string
17
+ for scanner .Scan () {
18
+ txtlines = append (txtlines , scanner .Text ())
19
+ }
20
+ file .Close ()
21
+ return txtlines
22
+ }
You can’t perform that action at this time.
0 commit comments