Compare commits
4 Commits
ab90e9c219
...
262f2aae90
Author | SHA1 | Date |
---|---|---|
Bill Ewanick | 262f2aae90 | |
Bill Ewanick | f9192bc541 | |
Bill Ewanick | 454937e2b8 | |
Bill Ewanick | 19b263e7e9 |
|
@ -78,6 +78,9 @@
|
|||
] ++ (with pkgs; [
|
||||
# Scripts
|
||||
clean
|
||||
|
||||
go
|
||||
gofumpt
|
||||
]);
|
||||
|
||||
shellHook = ''
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
res := canVisitAllRooms([][]int{{1, 3}, {3, 0, 1}, {2}, {0}})
|
||||
fmt.Printf("%+v\n", res)
|
||||
}
|
||||
|
||||
func canVisitAllRooms(rooms [][]int) bool {
|
||||
if len(rooms) > 0 && len(rooms[0]) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
keys := getAllKeys(0, make(map[int]struct{}), rooms)
|
||||
keys[0] = struct{}{}
|
||||
|
||||
for i := 0; i < len(rooms); i++ {
|
||||
if _, ok := keys[i]; !ok {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
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 := seen[rooms[index][j]]; ok {
|
||||
continue
|
||||
} else {
|
||||
seen[rooms[index][j]] = struct{}{}
|
||||
}
|
||||
keys[rooms[index][j]] = struct{}{}
|
||||
insideKeys := getAllKeys(rooms[index][j], seen, rooms)
|
||||
for k := range insideKeys {
|
||||
keys[k] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
{-
|
||||
n! means n x (n - 1) x ... x 3 x 2 x 1.
|
||||
For example, 10! = 10 x 9 x ... x 3 x 2 x 1 = 3628800,
|
||||
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
|
||||
Find the sum of the digits in the number 100!.
|
||||
-}
|
||||
|
||||
import Data.Char (digitToInt)
|
||||
|
||||
read' :: Integer -> String
|
||||
read' = show
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
print $ "Answer: " <> show ans
|
||||
|
||||
ans :: Int
|
||||
ans = sum $ map digitToInt $ read' $ product [1..100]
|
Loading…
Reference in New Issue