Day12 without Check for Test Routes

This commit is contained in:
Karl Spickermann 2021-12-12 16:16:32 +01:00
parent f670d107e8
commit 0eb93030db
3 changed files with 4 additions and 22 deletions

View File

@ -21,17 +21,10 @@ type stepTracking struct {
func main() {
args := os.Args[1:]
input, err := helper.GetInput(args[0])
input2, err := helper.GetInput("day12TestPart2Routes.txt")
if err != nil {
fmt.Println(err)
}
testRoutesPart2 := make([][]string, 0)
for _, line := range input2 {
splitLine := strings.Split(line, ",")
testRoutesPart2 = append(testRoutesPart2, splitLine)
}
routeMap := make(map[string][]string)
for _, line := range input {
splitLine := strings.Split(line, "-")
@ -46,29 +39,18 @@ func main() {
//part1
allRoutesCounter := 0
getRoute(&routeMap, []string{"start"}, &allRoutesCounter, 1, &testRoutesPart2)
getRoute(&routeMap, []string{"start"}, &allRoutesCounter, 1)
fmt.Println(allRoutesCounter)
//part2
allRoutesCounter = 0
getRoute(&routeMap, []string{"start"}, &allRoutesCounter, 2, &testRoutesPart2)
getRoute(&routeMap, []string{"start"}, &allRoutesCounter, 2)
fmt.Println(allRoutesCounter)
fmt.Println(len(testRoutesPart2))
fmt.Println()
for _, route := range testRoutesPart2 {
fmt.Println(route)
}
}
func getRoute(routeMap *map[string][]string, drivenRoute []string, allRoutesCounter *int, part int, testRoutesPart2 *[][]string) {
func getRoute(routeMap *map[string][]string, drivenRoute []string, allRoutesCounter *int, part int) {
if drivenRoute[len(drivenRoute)-1] == "end" {
*allRoutesCounter++
for i, route := range *testRoutesPart2 {
if helper.EqualStringArray(route, drivenRoute) {
*testRoutesPart2 = append((*testRoutesPart2)[:i], (*testRoutesPart2)[i+1:]...)
}
}
return
}
@ -84,7 +66,7 @@ func getRoute(routeMap *map[string][]string, drivenRoute []string, allRoutesCoun
for _, step := range possibleNextSteps {
newDrivenRoute := append(drivenRoute, step)
getRoute(routeMap, newDrivenRoute, allRoutesCounter, part, testRoutesPart2)
getRoute(routeMap, newDrivenRoute, allRoutesCounter, part)
}
}

BIN
src/day8/day8.exe Normal file

Binary file not shown.

BIN
src/day9/day9.exe Normal file

Binary file not shown.