a lot of (adapting to) renaming

This commit is contained in:
Stefan Harmuth 2020-12-26 10:49:31 +01:00
parent 14a6f70b97
commit 8767e8bfeb
12 changed files with 68 additions and 68 deletions

View File

@ -1,8 +1,8 @@
package day01 package day01
import tools "shtools" import "tools"
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
line := puzzle.GetInputArray()[0] line := puzzle.GetInputArray()[0]
answer := 0 answer := 0
for _, c := range line { for _, c := range line {
@ -16,7 +16,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
return answer return answer
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
line := puzzle.GetInputArray()[0] line := puzzle.GetInputArray()[0]
answer := 0 answer := 0
for x, c := range line { for x, c := range line {

View File

@ -1,12 +1,12 @@
package day02 package day02
import ( import (
tools "shtools"
"strconv" "strconv"
"strings" "strings"
"tools"
) )
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
sqm := 0 sqm := 0
for _, line := range puzzle.GetInputArray() { for _, line := range puzzle.GetInputArray() {
dim := strings.Split(line, "x") dim := strings.Split(line, "x")
@ -33,7 +33,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
return sqm return sqm
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
length := 0 length := 0
for _, line := range puzzle.GetInputArray() { for _, line := range puzzle.GetInputArray() {
dim := strings.Split(line, "x") dim := strings.Split(line, "x")

View File

@ -1,10 +1,10 @@
package day03 package day03
import ( import (
tools "shtools" "tools"
) )
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
x, y := 0, 0 x, y := 0, 0
houses := make(map[int]map[int]bool) houses := make(map[int]map[int]bool)
@ -35,7 +35,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
return houseCount return houseCount
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
x, y := [2]int{0, 0}, [2]int{0, 0} x, y := [2]int{0, 0}, [2]int{0, 0}
turn := 0 turn := 0
houses := make(map[int]map[int]bool) houses := make(map[int]map[int]bool)

View File

@ -3,9 +3,9 @@ package day04
import ( import (
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
tools "shtools"
"strconv" "strconv"
"strings" "strings"
"tools"
) )
func findMd5SumStartsWith(secretStart string, start string) int { func findMd5SumStartsWith(secretStart string, start string) int {
@ -25,13 +25,13 @@ func findMd5SumStartsWith(secretStart string, start string) int {
return -1 return -1
} }
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
secretStart := puzzle.GetInputArray()[0] secretStart := puzzle.GetInputArray()[0]
return findMd5SumStartsWith(secretStart, "00000") return findMd5SumStartsWith(secretStart, "00000")
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
secretStart := puzzle.GetInputArray()[0] secretStart := puzzle.GetInputArray()[0]
return findMd5SumStartsWith(secretStart, "000000") return findMd5SumStartsWith(secretStart, "000000")

View File

@ -2,7 +2,7 @@ package day05
import ( import (
"bytes" "bytes"
tools "shtools" "tools"
) )
var vowels = []byte{'a', 'e', 'i', 'o', 'u'} var vowels = []byte{'a', 'e', 'i', 'o', 'u'}
@ -57,7 +57,7 @@ func stringIsNiceP2(toTest []byte) bool {
return spacedChar && doubleRepeat return spacedChar && doubleRepeat
} }
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
niceCount := 0 niceCount := 0
for _, toCheck := range puzzle.GetInputArray() { for _, toCheck := range puzzle.GetInputArray() {
if stringIsNiceP1([]byte(toCheck)) { if stringIsNiceP1([]byte(toCheck)) {
@ -68,7 +68,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
return niceCount return niceCount
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
niceCount := 0 niceCount := 0
for _, toCheck := range puzzle.GetInputArray() { for _, toCheck := range puzzle.GetInputArray() {
if stringIsNiceP2([]byte(toCheck)) { if stringIsNiceP2([]byte(toCheck)) {

View File

@ -1,12 +1,12 @@
package day06 package day06
import ( import (
tools "shtools"
"strconv" "strconv"
"strings" "strings"
"tools"
) )
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
grid := make(map[int]map[int]bool) grid := make(map[int]map[int]bool)
for y := 0; y < 1000; y++ { for y := 0; y < 1000; y++ {
grid[y] = make(map[int]bool) grid[y] = make(map[int]bool)
@ -17,8 +17,8 @@ func Part1(puzzle tools.Puzzle) interface{} {
var values []string var values []string
var command, start, end string var command, start, end string
var a_start, a_end []string var aStart, aEnd []string
var start_x, start_y, end_x, end_y int var startX, startY, endX, endY int
for _, instruction := range puzzle.GetInputArray() { for _, instruction := range puzzle.GetInputArray() {
values = strings.Split(instruction, " ") values = strings.Split(instruction, " ")
@ -32,15 +32,15 @@ func Part1(puzzle tools.Puzzle) interface{} {
end = values[4] end = values[4]
} }
a_start = strings.Split(start, ",") aStart = strings.Split(start, ",")
a_end = strings.Split(end, ",") aEnd = strings.Split(end, ",")
start_x, _ = strconv.Atoi(a_start[0]) startX, _ = strconv.Atoi(aStart[0])
start_y, _ = strconv.Atoi(a_start[1]) startY, _ = strconv.Atoi(aStart[1])
end_x, _ = strconv.Atoi(a_end[0]) endX, _ = strconv.Atoi(aEnd[0])
end_y, _ = strconv.Atoi(a_end[1]) endY, _ = strconv.Atoi(aEnd[1])
for x := start_x; x <= end_x; x++ { for x := startX; x <= endX; x++ {
for y := start_y; y <= end_y; y++ { for y := startY; y <= endY; y++ {
switch command { switch command {
case "toggle": case "toggle":
grid[x][y] = !grid[x][y] grid[x][y] = !grid[x][y]
@ -65,7 +65,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
return onCount return onCount
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
grid := make(map[int]map[int]int) grid := make(map[int]map[int]int)
for y := 0; y < 1000; y++ { for y := 0; y < 1000; y++ {
grid[y] = make(map[int]int) grid[y] = make(map[int]int)
@ -76,8 +76,8 @@ func Part2(puzzle tools.Puzzle) interface{} {
var values []string var values []string
var command, start, end string var command, start, end string
var a_start, a_end []string var aStart, aEnd []string
var start_x, start_y, end_x, end_y int var startX, startY, endX, endY int
for _, instruction := range puzzle.GetInputArray() { for _, instruction := range puzzle.GetInputArray() {
values = strings.Split(instruction, " ") values = strings.Split(instruction, " ")
@ -91,15 +91,15 @@ func Part2(puzzle tools.Puzzle) interface{} {
end = values[4] end = values[4]
} }
a_start = strings.Split(start, ",") aStart = strings.Split(start, ",")
a_end = strings.Split(end, ",") aEnd = strings.Split(end, ",")
start_x, _ = strconv.Atoi(a_start[0]) startX, _ = strconv.Atoi(aStart[0])
start_y, _ = strconv.Atoi(a_start[1]) startY, _ = strconv.Atoi(aStart[1])
end_x, _ = strconv.Atoi(a_end[0]) endX, _ = strconv.Atoi(aEnd[0])
end_y, _ = strconv.Atoi(a_end[1]) endY, _ = strconv.Atoi(aEnd[1])
for x := start_x; x <= end_x; x++ { for x := startX; x <= endX; x++ {
for y := start_y; y <= end_y; y++ { for y := startY; y <= endY; y++ {
switch command { switch command {
case "toggle": case "toggle":
grid[x][y] += 2 grid[x][y] += 2

View File

@ -1,9 +1,9 @@
package day07 package day07
import ( import (
tools "shtools"
"strconv" "strconv"
"strings" "strings"
"tools"
) )
func calcWires(wires map[string]uint16, input []string, ignoreInputWire string) map[string]uint16 { func calcWires(wires map[string]uint16, input []string, ignoreInputWire string) map[string]uint16 {
@ -85,14 +85,14 @@ func calcWires(wires map[string]uint16, input []string, ignoreInputWire string)
return wires return wires
} }
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
input := puzzle.GetInputArray() input := puzzle.GetInputArray()
wires := make(map[string]uint16) wires := make(map[string]uint16)
wires = calcWires(wires, input, "") wires = calcWires(wires, input, "")
return int(wires["a"]) return int(wires["a"])
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
input := puzzle.GetInputArray() input := puzzle.GetInputArray()
wires := make(map[string]uint16) wires := make(map[string]uint16)
wires = calcWires(wires, input, "") wires = calcWires(wires, input, "")

View File

@ -2,10 +2,10 @@ package day08
import ( import (
"encoding/hex" "encoding/hex"
tools "shtools" "tools"
) )
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
answer := 0 answer := 0
for _, line := range puzzle.GetInputArray() { for _, line := range puzzle.GetInputArray() {
@ -33,7 +33,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
return answer return answer
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
answer := 0 answer := 0
for _, line := range puzzle.GetInputArray() { for _, line := range puzzle.GetInputArray() {

View File

@ -2,9 +2,9 @@ package day09
import ( import (
"math" "math"
tools "shtools"
"strconv" "strconv"
"strings" "strings"
"tools"
) )
func getDistanceMap(input []string) ([]string, map[string]map[string]int) { func getDistanceMap(input []string) ([]string, map[string]map[string]int) {
@ -79,14 +79,14 @@ func getMinMaxDistances(permutations [][]string, distances map[string]map[string
return minDistance, maxDistance return minDistance, maxDistance
} }
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
cities, distances := getDistanceMap(puzzle.GetInputArray()) cities, distances := getDistanceMap(puzzle.GetInputArray())
minDistance, _ := getMinMaxDistances(cityPermutations(cities), distances) minDistance, _ := getMinMaxDistances(cityPermutations(cities), distances)
return minDistance return minDistance
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
cities, distances := getDistanceMap(puzzle.GetInputArray()) cities, distances := getDistanceMap(puzzle.GetInputArray())
_, maxDistance := getMinMaxDistances(cityPermutations(cities), distances) _, maxDistance := getMinMaxDistances(cityPermutations(cities), distances)

View File

@ -1,7 +1,7 @@
package day10 package day10
import ( import (
tools "shtools" "tools"
) )
func lookAndSay(look []int) (say []int) { func lookAndSay(look []int) (say []int) {
@ -22,7 +22,7 @@ func lookAndSay(look []int) (say []int) {
return say return say
} }
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
look := puzzle.GetInput2DArrayInt()[0] look := puzzle.GetInput2DArrayInt()[0]
for i := 0; i < 40; i++ { for i := 0; i < 40; i++ {
@ -32,7 +32,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
return len(look) return len(look)
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
look := puzzle.GetInput2DArrayInt()[0] look := puzzle.GetInput2DArrayInt()[0]
for i := 0; i < 50; i++ { for i := 0; i < 50; i++ {

View File

@ -2,7 +2,7 @@ package day11
import ( import (
"fmt" "fmt"
tools "shtools" "tools"
) )
func incrementPassword(password []byte) { func incrementPassword(password []byte) {
@ -46,7 +46,7 @@ func checkPasswordValid(password []byte) bool {
return ascendingTripple && doubleDouble return ascendingTripple && doubleDouble
} }
func Part1(puzzle tools.Puzzle) interface{} { func Part1(puzzle tools.AoCPuzzle) interface{} {
currentPassword := []byte(puzzle.GetInputArray()[0]) currentPassword := []byte(puzzle.GetInputArray()[0])
for !checkPasswordValid(currentPassword) { for !checkPasswordValid(currentPassword) {
@ -56,7 +56,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
return fmt.Sprintf("%s", string(currentPassword)) return fmt.Sprintf("%s", string(currentPassword))
} }
func Part2(puzzle tools.Puzzle) interface{} { func Part2(puzzle tools.AoCPuzzle) interface{} {
currentPassword := []byte(Part1(puzzle).(string)) currentPassword := []byte(Part1(puzzle).(string))
incrementPassword(currentPassword) incrementPassword(currentPassword)

30
main.go
View File

@ -16,10 +16,10 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
tools "shtools" "tools"
) )
var dayFunctions map[int]map[int]func(puzzle tools.Puzzle) interface{} var dayFunctions map[int]map[int]func(puzzle tools.AoCPuzzle) interface{}
var day int var day int
var part int var part int
var test bool var test bool
@ -28,44 +28,44 @@ var timeitNumber int
var myDir, _ = filepath.Abs(filepath.Dir(os.Args[0])) var myDir, _ = filepath.Abs(filepath.Dir(os.Args[0]))
func initDayFunctions() { func initDayFunctions() {
dayFunctions = make(map[int]map[int]func(puzzle tools.Puzzle) interface{}, 25) dayFunctions = make(map[int]map[int]func(puzzle tools.AoCPuzzle) interface{}, 25)
dayFunctions[1] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2) dayFunctions[1] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
dayFunctions[1][1] = day01.Part1 dayFunctions[1][1] = day01.Part1
dayFunctions[1][2] = day01.Part2 dayFunctions[1][2] = day01.Part2
dayFunctions[2] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2) dayFunctions[2] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
dayFunctions[2][1] = day02.Part1 dayFunctions[2][1] = day02.Part1
dayFunctions[2][2] = day02.Part2 dayFunctions[2][2] = day02.Part2
dayFunctions[3] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2) dayFunctions[3] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
dayFunctions[3][1] = day03.Part1 dayFunctions[3][1] = day03.Part1
dayFunctions[3][2] = day03.Part2 dayFunctions[3][2] = day03.Part2
dayFunctions[4] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2) dayFunctions[4] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
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 tools.Puzzle) interface{}, 2) dayFunctions[5] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
dayFunctions[5][1] = day05.Part1 dayFunctions[5][1] = day05.Part1
dayFunctions[5][2] = day05.Part2 dayFunctions[5][2] = day05.Part2
dayFunctions[6] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2) dayFunctions[6] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
dayFunctions[6][1] = day06.Part1 dayFunctions[6][1] = day06.Part1
dayFunctions[6][2] = day06.Part2 dayFunctions[6][2] = day06.Part2
dayFunctions[7] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2) dayFunctions[7] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
dayFunctions[7][1] = day07.Part1 dayFunctions[7][1] = day07.Part1
dayFunctions[7][2] = day07.Part2 dayFunctions[7][2] = day07.Part2
dayFunctions[8] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2) dayFunctions[8] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
dayFunctions[8][1] = day08.Part1 dayFunctions[8][1] = day08.Part1
dayFunctions[8][2] = day08.Part2 dayFunctions[8][2] = day08.Part2
dayFunctions[9] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2) dayFunctions[9] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
dayFunctions[9][1] = day09.Part1 dayFunctions[9][1] = day09.Part1
dayFunctions[9][2] = day09.Part2 dayFunctions[9][2] = day09.Part2
dayFunctions[10] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2) dayFunctions[10] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
dayFunctions[10][1] = day10.Part1 dayFunctions[10][1] = day10.Part1
dayFunctions[10][2] = day10.Part2 dayFunctions[10][2] = day10.Part2
dayFunctions[11] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2) dayFunctions[11] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
dayFunctions[11][1] = day11.Part1 dayFunctions[11][1] = day11.Part1
dayFunctions[11][2] = day11.Part2 dayFunctions[11][2] = day11.Part2
} }
func execute(thisDay int) { func execute(thisDay int) {
p := tools.Puzzle{} p := tools.AoCPuzzle{}
if test { if test {
p.FromFile = fmt.Sprintf("%s/inputs/%d_test", myDir, thisDay) p.FromFile = fmt.Sprintf("%s/inputs/%d_test", myDir, thisDay)
} else { } else {