2024-07-24 14:29:59 +00:00
|
|
|
package aoc2015
|
|
|
|
|
2024-07-24 18:03:39 +00:00
|
|
|
import (
|
|
|
|
"aoc/internal/utility"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const vowels = "aeiou"
|
|
|
|
|
|
|
|
func day05part1(in string) int {
|
|
|
|
m := utility.RuneMap(in)
|
|
|
|
|
|
|
|
inVowels := 0
|
|
|
|
for _, v := range vowels {
|
|
|
|
inVowels += m[v]
|
|
|
|
}
|
|
|
|
if inVowels < 3 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
doubled := false
|
|
|
|
for i := 1; i < len(in); i++ {
|
|
|
|
if in[i-1] == in[i] {
|
|
|
|
doubled = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !doubled {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, set := range []string{"ab", "cd", "pq", "xy"} {
|
|
|
|
if strings.Contains(in, set) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func day05part2(in string) int {
|
|
|
|
doubled := false
|
|
|
|
for i := 1; i < len(in); i++ {
|
|
|
|
if strings.Contains(in[i+1:], in[i-1:i+1]) {
|
|
|
|
doubled = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !doubled {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 2; i < len(in); i++ {
|
|
|
|
if in[i-2] == in[i] {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
2024-07-24 14:29:59 +00:00
|
|
|
|
|
|
|
func day05() {
|
2024-07-24 18:03:39 +00:00
|
|
|
in := utility.GetLines("input/2015/05")
|
|
|
|
var p1, p2 int
|
|
|
|
for _, line := range in {
|
|
|
|
p1 += day05part1(line)
|
|
|
|
p2 += day05part2(line)
|
|
|
|
}
|
|
|
|
fmt.Println(p1)
|
|
|
|
fmt.Println(p2)
|
2024-07-24 14:29:59 +00:00
|
|
|
}
|