File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "bufio"
5+ "errors"
6+ "fmt"
7+ "os"
8+ "strings"
9+ )
10+
11+ type InputType int
12+
13+ const (
14+ example InputType = iota
15+ input
16+ )
17+
18+ const (
19+ inputPath string = "../../data/input"
20+ examplePath string = "../../data/example"
21+ )
22+
23+ var inputs map [InputType ]string = map [InputType ]string {
24+ example : examplePath ,
25+ input : inputPath ,
26+ }
27+
28+ func get_04_data (version InputType ) ([][]string , error ) {
29+ path , ok := inputs [version ]
30+ if ! ok {
31+ return [][]string {}, fmt .Errorf ("Cannot find path" )
32+ }
33+ file , err := os .Open (path )
34+ if err != nil {
35+ return nil , fmt .Errorf ("failed to open file: %w" , err )
36+ }
37+ defer file .Close ()
38+
39+ var data [][]string
40+
41+ scanner := bufio .NewScanner (file )
42+
43+ for scanner .Scan () {
44+ line := scanner .Text ()
45+
46+ fields := strings .Fields (line )
47+
48+ data = append (data , fields )
49+ }
50+
51+ if err := scanner .Err (); err != nil {
52+ return nil , fmt .Errorf ("error reading file: %w" , err )
53+ }
54+
55+ return data , nil
56+ }
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import "testing"
4+
5+ func test_simple (t * testing.T ) {
6+ if 1 != 1 {
7+ t .Fatal ("yikes" )
8+ }
9+ }
Original file line number Diff line number Diff line change 1+ MMMSXXMASM
2+ MSAMXMSMSA
3+ AMXSXMAAMM
4+ MSAMASMSMX
5+ XMASAMXAMM
6+ XXAMMXXAMA
7+ SMSMSASXSS
8+ SAXAMASAAA
9+ MAMMMXMMMM
10+ MXMXAXMASX
You can’t perform that action at this time.
0 commit comments