From 5fa98c8f55ee3ee22dc4007ad61e74ce55c08466 Mon Sep 17 00:00:00 2001 From: Ben Charlton Date: Wed, 2 Dec 2020 18:56:19 +0000 Subject: [PATCH] day 2 --- 02/02.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 02/02.py diff --git a/02/02.py b/02/02.py new file mode 100644 index 0000000..df13eeb --- /dev/null +++ b/02/02.py @@ -0,0 +1,33 @@ +#!/usr/bin/python3 + +import sys + +ints = [] +for line in sys.stdin: + instructions = line.rstrip().split(' ') + + c = instructions[0].split('-') + c_min = int(c[0]) + c_max = int(c[1]) + c_char = instructions[1][0] + pw = instructions[2] + + # Part 1 test + count = 0 + for c in pw: + if c == c_char: + count = count + 1 + + if c_min <= count <= c_max: + print(1, pw) + + # Part 2 test + count2 = 0 + if c_min <= len(pw) and pw[c_min - 1] == c_char: + count2 = count2 + 1 + + if c_max <= len(pw) and pw[c_max - 1] == c_char: + count2 = count2 + 1 + + if count2 == 1: + print(2, pw) \ No newline at end of file