2017: d04: ex2: add solution
This commit is contained in:
parent
48d50b56c6
commit
d473d73f53
1 changed files with 23 additions and 0 deletions
23
2017/d04/ex2/ex2.py
Executable file
23
2017/d04/ex2/ex2.py
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def solve(input: str) -> int:
|
||||
def parse(input: str) -> list[list[str]]:
|
||||
return [line.split() for line in input.splitlines()]
|
||||
|
||||
def validate_passphrase(passphrase: list[str]) -> bool:
|
||||
return len(set("".join(sorted(w)) for w in passphrase)) == len(passphrase)
|
||||
|
||||
passphrases = parse(input)
|
||||
return sum(map(validate_passphrase, passphrases))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue