Skip to content

Commit

Permalink
Add function that parses section IDs from the input
Browse files Browse the repository at this point in the history
  • Loading branch information
katzuv committed Dec 10, 2022
1 parent 77046a9 commit f234c09
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions puzzles/solutions/2022/d04/p1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import sys


def get_sections(input_text: str) -> tuple[tuple[set[int], set[int]]]:
"""
:param input_text: puzzle input
:return: tuple of (first section IDs, second section IDs) pairs
"""
pairs = input_text.splitlines()
sections = []
for pair in pairs:
pair_sections = []
for section_range in pair.split(","):
start, end = map(int, section_range.split("-"))
section_ids = set(range(start, end + 1))
pair_sections.append(section_ids)
sections.append(tuple(pair_sections))
return tuple(sections)


def get_answer(input_text: str):
raise NotImplementedError

Expand Down

0 comments on commit f234c09

Please sign in to comment.