1
0
Fork 0

Compare commits

..

4 Commits

Author SHA1 Message Date
Bill Ewanick 262f2aae90 Fix infinite loop
Co-authored-by: David Schlachter <https://github.com/davidschlachter>
2023-11-15 17:37:09 -05:00
Bill Ewanick f9192bc541 Run gofmt on code 2023-11-15 17:37:09 -05:00
Bill Ewanick 454937e2b8 Solve Project Euler 20 2023-11-15 17:37:09 -05:00
Bill Ewanick 19b263e7e9 L33t code 841 initial
Co-authored-by: David Schlachter <https://github.com/davidschlachter>
2023-11-15 17:36:12 -05:00
2 changed files with 18 additions and 15 deletions

View File

@ -80,6 +80,7 @@
clean
go
gofumpt
]);
shellHook = ''

View File

@ -3,7 +3,7 @@ package main
import "fmt"
func main() {
res := canVisitAllRooms([][]int{{1}, {2}, {}})
res := canVisitAllRooms([][]int{{1, 3}, {3, 0, 1}, {2}, {0}})
fmt.Printf("%+v\n", res)
}
@ -27,11 +27,13 @@ func getAllKeys(index int, seen map[int]struct{}, rooms [][]int) map[int]struct{
keys := map[int]struct{}{}
for j := 0; j < len(rooms[index]); j++ {
if _, ok := keys[rooms[index][j]]; ok {
if _, ok := seen[rooms[index][j]]; ok {
continue
} else {
seen[rooms[index][j]] = struct{}{}
}
keys[rooms[index][j]] = struct{}{}
insideKeys := getAllKeys(j, keys, rooms)
insideKeys := getAllKeys(rooms[index][j], seen, rooms)
for k := range insideKeys {
keys[k] = struct{}{}
}