Skip to content

Commit

Permalink
Fixing typos
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed-dash committed Jan 13, 2024
1 parent dac8451 commit 719a94c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4789,7 +4789,7 @@
"source": [
"### Day 12 Part 1\n",
"\n",
"The springs have fallen into disrepair. Our input is the condition record of which springs are damaged. But the input data is also damaged! We need to repair the damaged records.\n",
"The springs have fallen into disrepair. Our input is the condition records of which springs are damaged. But the input data is also damaged! We need to repair the damaged records.\n",
"\n",
"```text\n",
"???.### 1,1,3\n",
Expand All @@ -4803,37 +4803,38 @@
"Springs are arranged in rows. For each row, the condition record shows:\n",
"\n",
"- operational (`.`), damaged (`#`), or unknown (`?`) springs\n",
"- followed by counts of contiguous groups of damaged sprints, which accounts for every damaged spring\n",
"- followed by counts of contiguous groups of damaged springs, which accounts for every damaged spring\n",
"- groups are always separated by at least one operational spring\n",
"\n",
"**For each row, count all of the different arrangements of operational and broken springs that meet the given criteria. What is the sum of those counts?**\n",
"\n",
"**My solution:**\n",
"\n",
"We need to find all substitutions for `?` that result in valid records.\n",
"We need to find all substitutions for `?` that result in valid records. For each `?` we can substitute either `.` or `#`. We need to substitute for every `?` in the record, and the substitutions are only valid if they match the constraints given by the counts of damanaged springs. \n",
"\n",
"After parsing each row, I store the record in my `SpringRecord` [dataclass](https://aoc.just2good.co.uk/python/classes#dataclass). The count of possible valid arrangements is calculated by the [recursive](https://aoc.just2good.co.uk/python/recursion) `get_arrangements_count()` method.\n",
"I start by parsing each row. For each row, I create a `SpringRecord` [dataclass](https://aoc.just2good.co.uk/python/classes#dataclass). In this class:\n",
"\n",
"The method systematicalThe damaged_groups tuple defines the required lengths of contiguous blocks of #.\n",
"The current group index indicates which group (block of #) you are currently trying to complete.\n",
"This index helps in determining whether the current arrangement is in line with the damaged_groups requirements. For example, if you are working on the second group, the function knows to compare the current length of contiguous # characters with the second element in damaged_groups.ly explores every possible combination of `.`. and `#` for each `?` in the record. It keeps track of the current state (current character index, current group index, and length of the current group) to ensure the arrangement adheres to the constraints of `damaged_groups`.\n",
"- The `damaged_groups` tuple defines the required lengths of contiguous blocks of `#`.\n",
"- The count of possible valid arrangements is calculated by the [recursive](https://aoc.just2good.co.uk/python/recursion) `get_arrangements_count()` method.\n",
"\n",
"It works like this:\n",
"- `char_idx` stores the current position in the record string. At each step, we decide what the character at this position could be (`#` or `.`).\n",
"- The `damaged_groups` tuple defines the required lengths of contiguous blocks of `#`. The current group index (`curr_group_idx`) indicates which group (block of `#`) we are currently trying to complete.\n",
"\n",
"- `char_idx` stores the current position in the record string. At each step, we decide what the character at this position could be: either `#` or `.`.\n",
"- The `damaged_groups` tuple defines the required lengths of contiguous blocks of `#`. \n",
"- The current group index (`curr_group_idx`) indicates which group (block of `#`) we are currently trying to complete.\n",
"- `curr_group_len` keeps track of how many `#` characters have been consecutively placed in the current group.\n",
"\n",
"Together, these three pieces of information provide a complete snapshot of our progress through the string at any given recursion level. We know exactly where we are in the string, which group we are trying to fill, and how much of that group we have filled so far.\n",
"\n",
"- **Base case**\n",
" - When `char_idx` equals the length of the record, it means we've reached the end of the record.\n",
" - If `curr_group_idx` equals the length of `damaged_groups` and `curr_group_len` is `0`, all groups have been completed correctly, and this arrangement is valid.\n",
" - If `curr_group_idx` is the last group and `curr_group_len` equals the length of this last group, this is also a valid arrangement.\n",
" - In all other cases, the arrangement is invalid.\n",
" - If `curr_group_idx` equals the length of `damaged_groups` and `curr_group_len` is `0`, all groups have been completed correctly, and this arrangement is valid. Return `1`, so we can add it to the count of valid arrangements.\n",
" - If `curr_group_idx` is the last group and `curr_group_len` equals the length of this last group, this is also a valid arrangement. Return `1`.\n",
" - In all other cases, the arrangement is invalid, so return `0`.\n",
"\n",
"- **Recursion**\n",
" - The function iterates over each character (using `char_idx`) in the record. For each character position, it considers both possible states (`.` and `#`).\n",
" - We check if the character at `char_idx` in the record is either the same as the state being considered, or a `?`. I.e. because if the current character in the record is a `.`, then `.` is the only valid `char` to try. If the current character in the record is a `#`, then `#` is the only valid `char` to try. If the current character in the record is a `?`, then we can try substituting either `.` or `#`. Thus, whenever we encoutner `?`, our recursion branches into two paths.\n",
" - We check if the character at `char_idx` in the record is either the same as the state being considered, or a `?`. I.e. because if the current character in the record is a `.`, then `.` is the only valid `char` to try. If the current character in the record is a `#`, then `#` is the only valid `char` to try. If the current character in the record is a `?`, then we can try substituting either `.` or `#`. Thus, whenever we encounter `?`, our recursion branches.\n",
" - If the considered state is `.`, then there are two cases: 1) `curr_group_len` is `0`, which means we are not currently counting a group of `#`, so we can safely proceed to the next character. And 2) `curr_group_len` equals the length of the current group in `damaged_groups`, meaning we've completed a group and can proceed to the next group.\n",
" - If the considered state is `#`, then we're extending (or beginning) the current group. We increment `curr_group_len` and proceed to the next character.\n",
"\n",
Expand Down

0 comments on commit 719a94c

Please sign in to comment.