-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1.go
51 lines (43 loc) · 881 Bytes
/
day1.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
package main
import (
"fmt"
"strconv"
"strings"
"unicode"
"github.com/Alex-Waring/AoC/utils"
)
func main() {
lines := utils.ReadInput("input.txt")
numbers := map[string]string{
"one": "1",
"two": "2",
"three": "3",
"four": "4",
"five": "5",
"six": "6",
"seven": "7",
"eight": "8",
"nine": "9",
}
_lines := []string{}
for _, line := range lines {
_numbers := []string{}
for index, charecter := range line {
if unicode.IsNumber(charecter) {
_numbers = append(_numbers, string(charecter))
}
for word, number := range numbers {
if strings.HasPrefix(line[index:], word) {
_numbers = append(_numbers, number)
}
}
}
_lines = append(_lines, (_numbers[0] + _numbers[len(_numbers)-1]))
}
var answer int
for _, line := range _lines {
_num, _ := strconv.Atoi(line)
answer += _num
}
fmt.Print(answer)
}