day05
This commit is contained in:
parent
21cd974566
commit
8c56c14706
80
day05/day05.go
Normal file
80
day05/day05.go
Normal 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
|
||||||
|
}
|
||||||
5
inputs/5_test
Normal file
5
inputs/5_test
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
ugknbfddgicrmopn
|
||||||
|
aaa
|
||||||
|
jchzalrnumimnmhp
|
||||||
|
haegwjzuvuyypxyu
|
||||||
|
dvszwmarrgswjwmb
|
||||||
4
main.go
4
main.go
@ -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) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user