8000 day 4 parses input · jamesjarvis/adventofcode@90fefde · GitHub
[go: up one dir, main page]

Skip to content

Commit 90fefde

Browse files
committed
day 4 parses input
1 parent e2a6ad9 commit 90fefde

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

04/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/jamesjarvis/adventofcode/04
2+
3+
go 1.17

04/input.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1

04/inputBoards.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
22 13 17 11 0
2+
8 2 23 4 24
3+
21 9 14 16 7
4+
6 10 3 18 5
5+
1 12 20 15 19
6+
7+
3 15 0 2 22
8+
9 18 13 17 5
9+
19 8 7 25 23
10+
20 11 10 24 4
11+
14 21 16 12 6
12+
13+
14 21 17 24 4
14+
10 16 15 9 19
15+
18 8 23 26 20
16+
22 11 13 6 5
17+
2 0 12 3 7

04/main.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package main
2+
3+
import (
4+
_ "embed"
5+
"fmt"
6+
"strconv"
7+
"strings"
8+
)
9+
10+
//go:embed input.txt
11+
var input string
12+
13+
//go:embed inputBoards.txt
14+
var inputBoards string
15+
16+
func main() {
17+
if input == "" {
18+
panic("input cannot be empty")
19+
}
20+
if inputBoards == "" {
21+
panic("inputBoards cannot be empty")
22+
}
23+
inputstrarr := strings.Split(input, ",")
24+
inputarr := make([]int, len(inputstrarr))
25+
for i, v := range inputstrarr {
26+
n, err := strconv.Atoi(v)
27+
if err != nil {
28+
panic(err)
29+
}
30+
inputarr[i] = n
31+
}
32+
33+
fmt.Println(inputarr)
34+
35+
boards := [][][]int{}
36+
37+
// string: " 3 15 0 2 22"
38+
// int: 1
39+
// float/real: 2.3
40+
// bool: true/false
41+
// arrays: [type, type]
42+
43+
boardsstrarr := strings.Split(inputBoards, "\n")
44+
45+
board := [][]int{}
46+
for _, line := range boardsstrarr {
47+
if line == "" {
48+
boards = append(boards, board)
49+
board = [][]int{}
50+
continue
51+
}
52+
vals := strings.Split(line, " ")
53+
54+
boardline := []int{}
55+
for _, val := range vals {
56+
if val == "" {
57+
continue
58+
}
59+
n, err := strconv.Atoi(val)
60+
if err != nil {
61+
panic(err)
62+
}
63+
boardline = append(boardline, n)
64+
}
65+
board = append(board, boardline)
66+
}
67+
68+
fmt.Println(boards)
69+
70+
// ox, co2 := getShit(inputstrarr)
71+
// fmt.Printf("Answer: %d\n", ox*co2)
72+
}

0 commit comments

Comments
 (0)
0