From d473d73f53d399cced5aa7c8715b9971fb87f556 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 9 May 2025 16:11:35 +0100 Subject: [PATCH] 2017: d04: ex2: add solution --- 2017/d04/ex2/ex2.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 2017/d04/ex2/ex2.py diff --git a/2017/d04/ex2/ex2.py b/2017/d04/ex2/ex2.py new file mode 100755 index 0000000..6279f97 --- /dev/null +++ b/2017/d04/ex2/ex2.py @@ -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()