This commit is contained in:
Stefan Harmuth 2020-12-22 10:42:24 +01:00
parent 21cd974566
commit 8c56c14706
4 changed files with 1089 additions and 0 deletions

80
day05/day05.go Normal file
View File

@ -0,0 +1,80 @@
package day05
import (
"aoc2015/aoclib"
"bytes"
)
var vowels = []byte{'a', 'e', 'i', 'o', 'u'}
var badComps = map[string]struct{}{
"ab": {},
"cd": {},
"pq": {},
"xy": {},
}
func stringIsNiceP1(toTest []byte) bool {
doubleChar := false
vowelCount := 0
for x, c := range toTest {
if x > 0 {
if toTest[x-1] == c {
doubleChar = true
}
if _, ok := badComps[string(toTest[x-1:x+1])]; ok {
return false
}
}
if bytes.Contains(vowels, []byte{c}) {
vowelCount++
}
}
if doubleChar && vowelCount >= 3 {
return true
}
return false
}
func stringIsNiceP2(toTest []byte) bool {
spacedChar := false
doubleRepeat := false
for x, c := range toTest {
if x > 1 {
if toTest[x-2] == c {
spacedChar = true
}
}
if x > 2 {
for i := 0; i < x-2; i++ {
if toTest[i] == toTest[x-1] && toTest[i+1] == toTest[x] {
doubleRepeat = true
}
}
}
}
return spacedChar && doubleRepeat
}
func Part1(puzzle aoclib.Puzzle) interface{} {
niceCount := 0
for _, toCheck := range puzzle.GetInputArray() {
if stringIsNiceP1([]byte(toCheck)) {
niceCount++
}
}
return niceCount
}
func Part2(puzzle aoclib.Puzzle) interface{} {
niceCount := 0
for _, toCheck := range puzzle.GetInputArray() {
if stringIsNiceP2([]byte(toCheck)) {
niceCount++
}
}
return niceCount
}

1000
inputs/5 Normal file

File diff suppressed because it is too large Load Diff

5
inputs/5_test Normal file
View File

@ -0,0 +1,5 @@
ugknbfddgicrmopn
aaa
jchzalrnumimnmhp
haegwjzuvuyypxyu
dvszwmarrgswjwmb

View File

@ -6,6 +6,7 @@ import (
"aoc2015/day02" "aoc2015/day02"
"aoc2015/day03" "aoc2015/day03"
"aoc2015/day04" "aoc2015/day04"
"aoc2015/day05"
"flag" "flag"
"fmt" "fmt"
"os" "os"
@ -34,6 +35,9 @@ func initDayFunctions() {
dayFunctions[4] = make(map[int]func(puzzle aoclib.Puzzle) interface{}) dayFunctions[4] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[4][1] = day04.Part1 dayFunctions[4][1] = day04.Part1
dayFunctions[4][2] = day04.Part2 dayFunctions[4][2] = day04.Part2
dayFunctions[5] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[5][1] = day05.Part1
dayFunctions[5][2] = day05.Part2
} }
func execute(thisDay int) { func execute(thisDay int) {