a lot of (adapting to) renaming
This commit is contained in:
parent
14a6f70b97
commit
8767e8bfeb
@ -1,8 +1,8 @@
|
||||
package day01
|
||||
|
||||
import tools "shtools"
|
||||
import "tools"
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
line := puzzle.GetInputArray()[0]
|
||||
answer := 0
|
||||
for _, c := range line {
|
||||
@ -16,7 +16,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
|
||||
return answer
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
line := puzzle.GetInputArray()[0]
|
||||
answer := 0
|
||||
for x, c := range line {
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
package day02
|
||||
|
||||
import (
|
||||
tools "shtools"
|
||||
"strconv"
|
||||
"strings"
|
||||
"tools"
|
||||
)
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
sqm := 0
|
||||
for _, line := range puzzle.GetInputArray() {
|
||||
dim := strings.Split(line, "x")
|
||||
@ -33,7 +33,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
|
||||
return sqm
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
length := 0
|
||||
for _, line := range puzzle.GetInputArray() {
|
||||
dim := strings.Split(line, "x")
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
package day03
|
||||
|
||||
import (
|
||||
tools "shtools"
|
||||
"tools"
|
||||
)
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
x, y := 0, 0
|
||||
houses := make(map[int]map[int]bool)
|
||||
|
||||
@ -35,7 +35,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
|
||||
return houseCount
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
x, y := [2]int{0, 0}, [2]int{0, 0}
|
||||
turn := 0
|
||||
houses := make(map[int]map[int]bool)
|
||||
|
||||
@ -3,9 +3,9 @@ package day04
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
tools "shtools"
|
||||
"strconv"
|
||||
"strings"
|
||||
"tools"
|
||||
)
|
||||
|
||||
func findMd5SumStartsWith(secretStart string, start string) int {
|
||||
@ -25,13 +25,13 @@ func findMd5SumStartsWith(secretStart string, start string) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
secretStart := puzzle.GetInputArray()[0]
|
||||
|
||||
return findMd5SumStartsWith(secretStart, "00000")
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
secretStart := puzzle.GetInputArray()[0]
|
||||
|
||||
return findMd5SumStartsWith(secretStart, "000000")
|
||||
|
||||
@ -2,7 +2,7 @@ package day05
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
tools "shtools"
|
||||
"tools"
|
||||
)
|
||||
|
||||
var vowels = []byte{'a', 'e', 'i', 'o', 'u'}
|
||||
@ -57,7 +57,7 @@ func stringIsNiceP2(toTest []byte) bool {
|
||||
return spacedChar && doubleRepeat
|
||||
}
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
niceCount := 0
|
||||
for _, toCheck := range puzzle.GetInputArray() {
|
||||
if stringIsNiceP1([]byte(toCheck)) {
|
||||
@ -68,7 +68,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
|
||||
return niceCount
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
niceCount := 0
|
||||
for _, toCheck := range puzzle.GetInputArray() {
|
||||
if stringIsNiceP2([]byte(toCheck)) {
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
package day06
|
||||
|
||||
import (
|
||||
tools "shtools"
|
||||
"strconv"
|
||||
"strings"
|
||||
"tools"
|
||||
)
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
grid := make(map[int]map[int]bool)
|
||||
for y := 0; y < 1000; y++ {
|
||||
grid[y] = make(map[int]bool)
|
||||
@ -17,8 +17,8 @@ func Part1(puzzle tools.Puzzle) interface{} {
|
||||
|
||||
var values []string
|
||||
var command, start, end string
|
||||
var a_start, a_end []string
|
||||
var start_x, start_y, end_x, end_y int
|
||||
var aStart, aEnd []string
|
||||
var startX, startY, endX, endY int
|
||||
|
||||
for _, instruction := range puzzle.GetInputArray() {
|
||||
values = strings.Split(instruction, " ")
|
||||
@ -32,15 +32,15 @@ func Part1(puzzle tools.Puzzle) interface{} {
|
||||
end = values[4]
|
||||
}
|
||||
|
||||
a_start = strings.Split(start, ",")
|
||||
a_end = strings.Split(end, ",")
|
||||
start_x, _ = strconv.Atoi(a_start[0])
|
||||
start_y, _ = strconv.Atoi(a_start[1])
|
||||
end_x, _ = strconv.Atoi(a_end[0])
|
||||
end_y, _ = strconv.Atoi(a_end[1])
|
||||
aStart = strings.Split(start, ",")
|
||||
aEnd = strings.Split(end, ",")
|
||||
startX, _ = strconv.Atoi(aStart[0])
|
||||
startY, _ = strconv.Atoi(aStart[1])
|
||||
endX, _ = strconv.Atoi(aEnd[0])
|
||||
endY, _ = strconv.Atoi(aEnd[1])
|
||||
|
||||
for x := start_x; x <= end_x; x++ {
|
||||
for y := start_y; y <= end_y; y++ {
|
||||
for x := startX; x <= endX; x++ {
|
||||
for y := startY; y <= endY; y++ {
|
||||
switch command {
|
||||
case "toggle":
|
||||
grid[x][y] = !grid[x][y]
|
||||
@ -65,7 +65,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
|
||||
return onCount
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
grid := make(map[int]map[int]int)
|
||||
for y := 0; y < 1000; y++ {
|
||||
grid[y] = make(map[int]int)
|
||||
@ -76,8 +76,8 @@ func Part2(puzzle tools.Puzzle) interface{} {
|
||||
|
||||
var values []string
|
||||
var command, start, end string
|
||||
var a_start, a_end []string
|
||||
var start_x, start_y, end_x, end_y int
|
||||
var aStart, aEnd []string
|
||||
var startX, startY, endX, endY int
|
||||
|
||||
for _, instruction := range puzzle.GetInputArray() {
|
||||
values = strings.Split(instruction, " ")
|
||||
@ -91,15 +91,15 @@ func Part2(puzzle tools.Puzzle) interface{} {
|
||||
end = values[4]
|
||||
}
|
||||
|
||||
a_start = strings.Split(start, ",")
|
||||
a_end = strings.Split(end, ",")
|
||||
start_x, _ = strconv.Atoi(a_start[0])
|
||||
start_y, _ = strconv.Atoi(a_start[1])
|
||||
end_x, _ = strconv.Atoi(a_end[0])
|
||||
end_y, _ = strconv.Atoi(a_end[1])
|
||||
aStart = strings.Split(start, ",")
|
||||
aEnd = strings.Split(end, ",")
|
||||
startX, _ = strconv.Atoi(aStart[0])
|
||||
startY, _ = strconv.Atoi(aStart[1])
|
||||
endX, _ = strconv.Atoi(aEnd[0])
|
||||
endY, _ = strconv.Atoi(aEnd[1])
|
||||
|
||||
for x := start_x; x <= end_x; x++ {
|
||||
for y := start_y; y <= end_y; y++ {
|
||||
for x := startX; x <= endX; x++ {
|
||||
for y := startY; y <= endY; y++ {
|
||||
switch command {
|
||||
case "toggle":
|
||||
grid[x][y] += 2
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package day07
|
||||
|
||||
import (
|
||||
tools "shtools"
|
||||
"strconv"
|
||||
"strings"
|
||||
"tools"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
input := puzzle.GetInputArray()
|
||||
wires := make(map[string]uint16)
|
||||
wires = calcWires(wires, input, "")
|
||||
return int(wires["a"])
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
input := puzzle.GetInputArray()
|
||||
wires := make(map[string]uint16)
|
||||
wires = calcWires(wires, input, "")
|
||||
|
||||
@ -2,10 +2,10 @@ package day08
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
tools "shtools"
|
||||
"tools"
|
||||
)
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
answer := 0
|
||||
|
||||
for _, line := range puzzle.GetInputArray() {
|
||||
@ -33,7 +33,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
|
||||
return answer
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
answer := 0
|
||||
|
||||
for _, line := range puzzle.GetInputArray() {
|
||||
|
||||
@ -2,9 +2,9 @@ package day09
|
||||
|
||||
import (
|
||||
"math"
|
||||
tools "shtools"
|
||||
"strconv"
|
||||
"strings"
|
||||
"tools"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
cities, distances := getDistanceMap(puzzle.GetInputArray())
|
||||
minDistance, _ := getMinMaxDistances(cityPermutations(cities), distances)
|
||||
|
||||
return minDistance
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
cities, distances := getDistanceMap(puzzle.GetInputArray())
|
||||
_, maxDistance := getMinMaxDistances(cityPermutations(cities), distances)
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package day10
|
||||
|
||||
import (
|
||||
tools "shtools"
|
||||
"tools"
|
||||
)
|
||||
|
||||
func lookAndSay(look []int) (say []int) {
|
||||
@ -22,7 +22,7 @@ func lookAndSay(look []int) (say []int) {
|
||||
return say
|
||||
}
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
look := puzzle.GetInput2DArrayInt()[0]
|
||||
|
||||
for i := 0; i < 40; i++ {
|
||||
@ -32,7 +32,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
|
||||
return len(look)
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
look := puzzle.GetInput2DArrayInt()[0]
|
||||
|
||||
for i := 0; i < 50; i++ {
|
||||
|
||||
@ -2,7 +2,7 @@ package day11
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
tools "shtools"
|
||||
"tools"
|
||||
)
|
||||
|
||||
func incrementPassword(password []byte) {
|
||||
@ -46,7 +46,7 @@ func checkPasswordValid(password []byte) bool {
|
||||
return ascendingTripple && doubleDouble
|
||||
}
|
||||
|
||||
func Part1(puzzle tools.Puzzle) interface{} {
|
||||
func Part1(puzzle tools.AoCPuzzle) interface{} {
|
||||
currentPassword := []byte(puzzle.GetInputArray()[0])
|
||||
|
||||
for !checkPasswordValid(currentPassword) {
|
||||
@ -56,7 +56,7 @@ func Part1(puzzle tools.Puzzle) interface{} {
|
||||
return fmt.Sprintf("%s", string(currentPassword))
|
||||
}
|
||||
|
||||
func Part2(puzzle tools.Puzzle) interface{} {
|
||||
func Part2(puzzle tools.AoCPuzzle) interface{} {
|
||||
currentPassword := []byte(Part1(puzzle).(string))
|
||||
|
||||
incrementPassword(currentPassword)
|
||||
|
||||
30
main.go
30
main.go
@ -16,10 +16,10 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"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 part int
|
||||
var test bool
|
||||
@ -28,44 +28,44 @@ var timeitNumber int
|
||||
var myDir, _ = filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
|
||||
func initDayFunctions() {
|
||||
dayFunctions = make(map[int]map[int]func(puzzle tools.Puzzle) interface{}, 25)
|
||||
dayFunctions[1] = make(map[int]func(puzzle tools.Puzzle) interface{}, 2)
|
||||
dayFunctions = make(map[int]map[int]func(puzzle tools.AoCPuzzle) interface{}, 25)
|
||||
dayFunctions[1] = make(map[int]func(puzzle tools.AoCPuzzle) interface{}, 2)
|
||||
dayFunctions[1][1] = day01.Part1
|
||||
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][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][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][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][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][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][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][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][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][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][2] = day11.Part2
|
||||
}
|
||||
|
||||
func execute(thisDay int) {
|
||||
p := tools.Puzzle{}
|
||||
p := tools.AoCPuzzle{}
|
||||
if test {
|
||||
p.FromFile = fmt.Sprintf("%s/inputs/%d_test", myDir, thisDay)
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user