-
Notifications
You must be signed in to change notification settings - Fork 0
/
advent1.go
102 lines (96 loc) · 3 KB
/
advent1.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import("fmt";"bufio";"os";"strings";"strconv")
func main(){
fmt.Println("Input coordinates:")
reader:= bufio.NewReader(os.Stdin)
sum:=0
for{
s,_ := reader.ReadString('\n')
s=strings.TrimSuffix(s,"\n")
first := -1
last := -1
l := len(s)
for i,c := range s{
//fmt.Println(int(c)-48)
_,err := strconv.Atoi(string(c))
if err==nil {
if(first==-1){
first = (int(c)-48)
last = (int(c)-48)
}else{last = (int(c)-48)}
}
if(c=='o'&&l>=i+3){
if(string(s[i:i+3])=="one"){
if(first==-1){
first = 1
last = 1
}else{last = 1}
}
}
if(c=='t'&&l>=i+3){
if(string(s[i:i+3])=="two"){
if(first==-1){
first = 2
last = 2
}else{last = 2}
}else if(l>=i+5){
if(string(s[i:i+5])=="three"){
if(first==-1){
first = 3
last = 3
}else{last = 3}
}
}
}
if(c=='f'&&l>=i+4){
if(string(s[i:i+4])=="four"){
if(first==-1){
first = 4
last = 4
}else{last = 4}
}else if(string(s[i:i+4])=="five"){
if(first==-1){
first = 5
last = 5
}else{last = 5}
}
}
if(c=='s'&&l>=i+3){
if(string(s[i:i+3])=="six"){
if(first==-1){
first = 6
last = 6
}else{last = 6}
}else if(l>=i+5){
if(string(s[i:i+5])=="seven"){
if(first==-1){
first = 7
last = 7
}else{last = 7}
}
}
}
if(c=='e'&&l>=i+5){
if(string(s[i:i+5])=="eight"){
if(first==-1){
first = 8
last = 8
}else{last = 8}
}
}
if(c=='n'&&l>=i+4){
if(string(s[i:i+4])=="nine"){
if(first==-1){
first = 9
last = 9
}else{last = 9}
}
}
}
if(first!=-1){
sum=sum+(first*10+last)
fmt.Printf("Thanks here: %s\t%d %d\n",s,(first*10+last),sum)
}
if(s=="end"){break}
}
}