Compare commits
No commits in common. "8e030c9d88d5b2ec9e4f4500f05942b85da5a65c" and "56a29c6d9abcd5fec2e05742063282a5b91bf287" have entirely different histories.
8e030c9d88
...
56a29c6d9a
|
@ -1,46 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from typing import Dict, List, Set
|
||||
|
||||
Map = Dict[str, Set[str]]
|
||||
|
||||
|
||||
def solve(input: List[str]) -> int:
|
||||
def parse() -> Map:
|
||||
res: Map = defaultdict(set)
|
||||
|
||||
for (start, to) in map(lambda s: s.split("-"), input):
|
||||
res[start].add(to)
|
||||
res[to].add(start)
|
||||
|
||||
return res
|
||||
|
||||
caves = parse()
|
||||
|
||||
def dfs(start: str, seen: Set[str] = set()) -> int:
|
||||
if start == "end":
|
||||
return 1
|
||||
|
||||
seen = seen | {start}
|
||||
res = 0
|
||||
|
||||
for dest in caves[start]:
|
||||
if dest in seen and dest.islower():
|
||||
continue
|
||||
res += dfs(dest, seen)
|
||||
|
||||
return res
|
||||
|
||||
return dfs("start")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,22 +0,0 @@
|
|||
ax-end
|
||||
xq-GF
|
||||
end-xq
|
||||
im-wg
|
||||
ax-ie
|
||||
start-ws
|
||||
ie-ws
|
||||
CV-start
|
||||
ng-wg
|
||||
ng-ie
|
||||
GF-ng
|
||||
ng-av
|
||||
CV-end
|
||||
ie-GF
|
||||
CV-ie
|
||||
im-xq
|
||||
start-GF
|
||||
GF-ws
|
||||
wg-LY
|
||||
CV-ws
|
||||
im-CV
|
||||
CV-wg
|
|
@ -1,49 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from typing import Dict, List, Set
|
||||
|
||||
Map = Dict[str, Set[str]]
|
||||
|
||||
|
||||
def solve(input: List[str]) -> int:
|
||||
def parse() -> Map:
|
||||
res: Map = defaultdict(set)
|
||||
|
||||
for (start, to) in map(lambda s: s.split("-"), input):
|
||||
res[start].add(to)
|
||||
res[to].add(start)
|
||||
|
||||
return res
|
||||
|
||||
caves = parse()
|
||||
|
||||
def dfs(start: str, seen: Set[str] = set(), has_doubled_back: bool = False) -> int:
|
||||
if start == "end":
|
||||
return 1
|
||||
|
||||
seen = seen | {start}
|
||||
res = 0
|
||||
|
||||
for dest in caves[start]:
|
||||
doubles_back = False
|
||||
if dest in seen and dest.islower():
|
||||
if has_doubled_back or dest == "start":
|
||||
continue
|
||||
doubles_back = True
|
||||
res += dfs(dest, seen, has_doubled_back or doubles_back)
|
||||
|
||||
return res
|
||||
|
||||
return dfs("start")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,22 +0,0 @@
|
|||
ax-end
|
||||
xq-GF
|
||||
end-xq
|
||||
im-wg
|
||||
ax-ie
|
||||
start-ws
|
||||
ie-ws
|
||||
CV-start
|
||||
ng-wg
|
||||
ng-ie
|
||||
GF-ng
|
||||
ng-av
|
||||
CV-end
|
||||
ie-GF
|
||||
CV-ie
|
||||
im-xq
|
||||
start-GF
|
||||
GF-ws
|
||||
wg-LY
|
||||
CV-ws
|
||||
im-CV
|
||||
CV-wg
|
Loading…
Reference in a new issue