Browse Source

account for shared starting and ending runes

master
Alexander Avery 1 year ago
parent
commit
3edddbd7fc
  1. 18
      day01.go

18
day01.go

@ -35,31 +35,31 @@ func findtextdigits(line string) []rune {
if strings.HasPrefix(line, "one") {
d = append(d, '1')
line = line[3:]
line = line[2:]
} else if strings.HasPrefix(line, "two") {
d = append(d, '2')
line = line[3:]
line = line[2:]
} else if strings.HasPrefix(line, "three") {
d = append(d, '3')
line = line[5:]
line = line[4:]
} else if strings.HasPrefix(line, "four") {
d = append(d, '4')
line = line[4:]
line = line[4:] // skip len("four") entirely because no digits start with 'r'
} else if strings.HasPrefix(line, "five") {
d = append(d, '5')
line = line[4:]
line = line[3:]
} else if strings.HasPrefix(line, "six") {
d = append(d, '6')
line = line[3:]
line = line[3:] // skip len("six") entirely because no digits start with 'x'
} else if strings.HasPrefix(line, "seven") {
d = append(d, '7')
line = line[5:]
line = line[4:]
} else if strings.HasPrefix(line, "eight") {
d = append(d, '8')
line = line[5:]
line = line[4:]
} else if strings.HasPrefix(line, "nine") {
d = append(d, '9')
line = line[4:]
line = line[3:]
} else {
line = line[1:]
}

Loading…
Cancel
Save