|
@@ -8,33 +8,32 @@ import (
|
|
|
"strconv"
|
|
|
)
|
|
|
|
|
|
-func readInput(file *os.File) ([]int, int) {
|
|
|
+func readInput(file *os.File) [3]int {
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
- numbers := []int{0}
|
|
|
- index := 0
|
|
|
- max := 0
|
|
|
+ var numbers [3]int
|
|
|
+ current := 0
|
|
|
|
|
|
for scanner.Scan() {
|
|
|
line := scanner.Text()
|
|
|
if line == "" {
|
|
|
- if numbers[index] > max {
|
|
|
- max = numbers[index]
|
|
|
+ for i := range numbers {
|
|
|
+ if current > numbers[i] {
|
|
|
+ current, numbers[i] = numbers[i], current
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- index++
|
|
|
- numbers = append(numbers, 0)
|
|
|
-
|
|
|
+ current = 0
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
if number, err := strconv.Atoi(line); err == nil {
|
|
|
- numbers[index] += number
|
|
|
+ current += number
|
|
|
} else {
|
|
|
log.Fatal("Numbers: ", err)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return numbers, max
|
|
|
+ return numbers
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
@@ -49,6 +48,7 @@ func main() {
|
|
|
|
|
|
}
|
|
|
|
|
|
- _, max := readInput(file)
|
|
|
- fmt.Println("Part1:", max)
|
|
|
+ numbers := readInput(file)
|
|
|
+ fmt.Println("Part1:", numbers[0])
|
|
|
+ fmt.Println("Part2:", numbers[0]+numbers[1]+numbers[2])
|
|
|
}
|