-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday05.go
69 lines (57 loc) · 1.79 KB
/
day05.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package day05
import (
"2023/day05/almanac"
"2023/day05/convertionMap"
"2023/day05/convertionMapList"
"log"
"strconv"
"strings"
)
type Day struct{}
func parseSeeds(line string) []int {
sNumbers := strings.Split(strings.TrimSpace(strings.Split(line, ":")[1]), " ")
seeds := make([]int, 0)
for _, sNumber := range sNumbers {
number, err := strconv.ParseInt(sNumber, 10, 64)
if err != nil {
log.Fatalf("Error while parsing the integet '%s'", sNumber)
}
seeds = append(seeds, int(number))
}
return seeds
}
func (d Day) GetInput(lines []string) interface{} {
seeds := parseSeeds(lines[0])
var convertionMaps [7]convertionMapList.ConvertionMapList
readingMap := -1
for i, line := range lines {
if line == "" || i == 0 {
continue
}
if strings.Contains(line, ":") {
readingMap++
convertionMaps[readingMap] = convertionMapList.ConvertionMapList{}
continue
}
sNumbers := strings.Split(strings.TrimSpace(line), " ")
numbers := make([]int, 0)
for _, sNumber := range sNumbers {
number, err := strconv.ParseInt(sNumber, 10, 64)
if err != nil {
log.Fatalf("Error while parsing the integet '%s'", sNumber)
}
numbers = append(numbers, int(number))
}
convertionMap := convertionMap.ConvertionMap{Source: numbers[1], Destination: numbers[0], Length: numbers[2]}
convertionMaps[readingMap] = convertionMapList.ConvertionMapList{List: append(convertionMaps[readingMap].List, convertionMap)}
}
return almanac.Almanac{Seeds: seeds, ConvertionMaps: convertionMaps}
}
func (d Day) SolvePart1(almanacI interface{}) int {
almanacPart := almanacI.(almanac.Almanac)
return almanacPart.GetLowestNearestLocationPart1()
}
func (d Day) SolvePart2(almanacI interface{}) int {
almanacPart := almanacI.(almanac.Almanac)
return almanacPart.GetLowestNearestLocationPart2()
}