Browse Source

Day 2 completed.

master
noirscape 1 year ago
parent
commit
a43dc65b2f
8 changed files with 2059 additions and 0 deletions
  1. +0
    -0
      1/puzzle 1/input.txt
  2. +0
    -0
      1/puzzle 1/main.py
  3. +0
    -0
      1/puzzle 2/input.txt
  4. +0
    -0
      1/puzzle 2/main.py
  5. +1000
    -0
      2/puzzle 1/input.txt
  6. +26
    -0
      2/puzzle 1/main.py
  7. +1000
    -0
      2/puzzle 2/input.txt
  8. +33
    -0
      2/puzzle 2/main.py

1/input.txt → 1/puzzle 1/input.txt View File


1/main.py → 1/puzzle 1/main.py View File


2/input.txt → 1/puzzle 2/input.txt View File


2/main.py → 1/puzzle 2/main.py View File


+ 1000
- 0
2/puzzle 1/input.txt
File diff suppressed because it is too large
View File


+ 26
- 0
2/puzzle 1/main.py View File

@ -0,0 +1,26 @@
import re
handle = open("input.txt", "r")
lines = handle.readlines()
def does_password_match(input_string, min_char, max_char, letter):
char_counter = 0
for char in input_string:
if char == letter:
char_counter += 1
if int(min_char) <= char_counter <= int(max_char):
return True
return False
counter = 0
for line in lines:
split_line = line.split(": ") # 0: criteria, 1: password
criteria_contents = split_line[0]
criteria_details = re.match(r"([0-9]+)-([0-9]+) (\w)", criteria_contents)
criteria_details = criteria_details.groups()
if does_password_match(split_line[1], criteria_details[0], criteria_details[1], criteria_details[2]):
counter += 1
print(counter)
handle.close()

+ 1000
- 0
2/puzzle 2/input.txt
File diff suppressed because it is too large
View File


+ 33
- 0
2/puzzle 2/main.py View File

@ -0,0 +1,33 @@
import re
handle = open("input.txt", "r")
lines = handle.readlines()
test_lines = ["1-3 a: abcde",
"1-3 b: cdefg",
"2-9 c: ccccccccc"]
def does_password_match(input_string, first_pos, second_pos, letter):
# -1 to account for no concept of index zero!
first_check = input_string[int(first_pos) - 1] == letter
second_check = input_string[int(second_pos) -1] == letter
if first_check and not second_check:
return True
if second_check and not first_check:
return True
return False
def main(lines):
counter = 0
for line in lines:
split_line = line.split(": ") # 0: criteria, 1: password
criteria_contents = split_line[0]
criteria_details = re.match(r"([0-9]+)-([0-9]+) (\w)", criteria_contents)
criteria_details = criteria_details.groups()
if does_password_match(split_line[1], criteria_details[0], criteria_details[1], criteria_details[2]):
counter += 1
print(counter)
main(lines)
handle.close()

Loading…
Cancel
Save