Browse Source

Day 6 completed.

master
noirscape 1 year ago
parent
commit
58a71f6897
4 changed files with 4213 additions and 0 deletions
  1. +2050
    -0
      6/puzzle 1/input.txt
  2. +51
    -0
      6/puzzle 1/main.py
  3. +2050
    -0
      6/puzzle 2/input.txt
  4. +62
    -0
      6/puzzle 2/main.py

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


+ 51
- 0
6/puzzle 1/main.py View File

@ -0,0 +1,51 @@
handle = open("input.txt", "r")
lines = [line.rstrip() for line in handle.readlines()]
test_lines = [
"abc",
"",
"a",
"b",
"c",
"",
"ab",
"ac",
"",
"a",
"a",
"a",
"a",
"",
"b",
""
]
def get_total_answers(line_group):
answers = []
for line in line_group:
for chara in line:
if chara not in answers:
answers.append(chara)
return len(answers)
def split_lines_into_groups(lines):
lines.append("")
split_groups = []
current_group = []
for line in lines:
if line != "":
current_group.append(line)
else:
split_groups.append(current_group)
current_group = []
return split_groups
def main(lines):
groups = split_lines_into_groups(lines)
total_answers_for_yes = 0
everyone_answers_yes = 0
for group in groups:
total_answers_for_yes += get_total_answers(group)
print(f"{total_answers_for_yes=}")
main(lines)
handle.close()

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


+ 62
- 0
6/puzzle 2/main.py View File

@ -0,0 +1,62 @@
handle = open("input.txt", "r")
lines = [line.rstrip() for line in handle.readlines()]
test_lines = [
"abc",
"",
"a",
"b",
"c",
"",
"ab",
"ac",
"",
"a",
"a",
"a",
"a",
"",
"b",
""
]
def get_total_answers(line_group):
answers = []
for line in line_group:
for chara in line:
if chara not in answers:
answers.append(chara)
return len(answers)
def get_all_yes_answers(line_group):
answers = set()
for idx, line in enumerate(line_group): # 1 line = 1 person
if idx == 0: # Special case for first person -> they get to set the base set of valid answers
answers = set(line)
else: # Otherwise, we go through the answers list and check it against their answers
for answer in answers:
answers = answers.intersection(line)
return len(answers)
def split_lines_into_groups(lines):
lines.append("")
split_groups = []
current_group = []
for line in lines:
if line != "":
current_group.append(line)
else:
split_groups.append(current_group)
current_group = []
return split_groups
def main(lines):
groups = split_lines_into_groups(lines)
total_answers_for_yes = 0
everyone_answers_yes = 0
for group in groups:
everyone_answers_yes += get_all_yes_answers(group)
total_answers_for_yes += get_total_answers(group)
print(f"{total_answers_for_yes=} {everyone_answers_yes=}")
main(lines)
handle.close()

Loading…
Cancel
Save