Day12 without Check for Test Routes
This commit is contained in:
parent
f670d107e8
commit
0eb93030db
|
@ -21,17 +21,10 @@ type stepTracking struct {
|
||||||
func main() {
|
func main() {
|
||||||
args := os.Args[1:]
|
args := os.Args[1:]
|
||||||
input, err := helper.GetInput(args[0])
|
input, err := helper.GetInput(args[0])
|
||||||
input2, err := helper.GetInput("day12TestPart2Routes.txt")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
testRoutesPart2 := make([][]string, 0)
|
|
||||||
for _, line := range input2 {
|
|
||||||
splitLine := strings.Split(line, ",")
|
|
||||||
testRoutesPart2 = append(testRoutesPart2, splitLine)
|
|
||||||
}
|
|
||||||
|
|
||||||
routeMap := make(map[string][]string)
|
routeMap := make(map[string][]string)
|
||||||
for _, line := range input {
|
for _, line := range input {
|
||||||
splitLine := strings.Split(line, "-")
|
splitLine := strings.Split(line, "-")
|
||||||
|
@ -46,29 +39,18 @@ func main() {
|
||||||
|
|
||||||
//part1
|
//part1
|
||||||
allRoutesCounter := 0
|
allRoutesCounter := 0
|
||||||
getRoute(&routeMap, []string{"start"}, &allRoutesCounter, 1, &testRoutesPart2)
|
getRoute(&routeMap, []string{"start"}, &allRoutesCounter, 1)
|
||||||
fmt.Println(allRoutesCounter)
|
fmt.Println(allRoutesCounter)
|
||||||
|
|
||||||
//part2
|
//part2
|
||||||
allRoutesCounter = 0
|
allRoutesCounter = 0
|
||||||
getRoute(&routeMap, []string{"start"}, &allRoutesCounter, 2, &testRoutesPart2)
|
getRoute(&routeMap, []string{"start"}, &allRoutesCounter, 2)
|
||||||
fmt.Println(allRoutesCounter)
|
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" {
|
if drivenRoute[len(drivenRoute)-1] == "end" {
|
||||||
*allRoutesCounter++
|
*allRoutesCounter++
|
||||||
for i, route := range *testRoutesPart2 {
|
|
||||||
if helper.EqualStringArray(route, drivenRoute) {
|
|
||||||
*testRoutesPart2 = append((*testRoutesPart2)[:i], (*testRoutesPart2)[i+1:]...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +66,7 @@ func getRoute(routeMap *map[string][]string, drivenRoute []string, allRoutesCoun
|
||||||
|
|
||||||
for _, step := range possibleNextSteps {
|
for _, step := range possibleNextSteps {
|
||||||
newDrivenRoute := append(drivenRoute, step)
|
newDrivenRoute := append(drivenRoute, step)
|
||||||
getRoute(routeMap, newDrivenRoute, allRoutesCounter, part, testRoutesPart2)
|
getRoute(routeMap, newDrivenRoute, allRoutesCounter, part)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user