From 207c27aea4bf1116d5d80ad18b3eeee2c0e31e26 Mon Sep 17 00:00:00 2001 From: kamoshi <18511281+kamoshi@users.noreply.github.com> Date: Wed, 2 Dec 2020 08:42:52 +0100 Subject: [PATCH] Create day02.py --- 2020/Python/day02.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 2020/Python/day02.py diff --git a/2020/Python/day02.py b/2020/Python/day02.py new file mode 100644 index 0000000..1f6576a --- /dev/null +++ b/2020/Python/day02.py @@ -0,0 +1,25 @@ +def part1(): + result = 0 + with open("input2.txt") as f: + for line in f: + (policy, char, passcode) = line.split() + min_p, max_p = policy.split("-") + number_of_char = passcode.count(char[0]) + if int(min_p) <= number_of_char <= int(max_p): + result += 1 + + print(result) + + +def part2(): + result = 0 + with open("input2.txt") as f: + for line in f: + (policy, char, passcode) = line.split() + min_p, max_p = policy.split("-") + if (passcode[int(min_p)-1] == char[0] and passcode[int(max_p)-1] != char[0]) or (passcode[int(min_p)-1] != char[0] and passcode[int(max_p)-1] == char[0]): + result += 1 + print(result) + +part1() +part2()