-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cff5e4
commit 94ec663
Showing
13 changed files
with
953 additions
and
814 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
.DS_Store | ||
__pycache__ | ||
.pytest_cache | ||
.coverage | ||
|
||
# virtual env | ||
venv | ||
|
||
# testplan report | ||
report.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## Hello! 👋 | ||
This is my [Advent of Code 2023](https://adventofcode.com/2023/) project! I code with python and test with [testplan](https://github.com/morganstanley/testplan). | ||
|
||
## How to Run | ||
### testplan | ||
```sh | ||
python tests/test_plan.py | ||
|
||
# display testplan report | ||
tpsreport display fromjson report/report.json | ||
``` | ||
|
||
### testplan with coverage | ||
```sh | ||
python tests/test_plan.py --coverage | ||
coverage report -m | ||
coverage html | ||
|
||
# now coverage report is under htmlcov/index.html | ||
``` | ||
|
||
## License | ||
See [License](LICENSE) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class Part1: | ||
NODE_KEY='AAA' | ||
MATCH_LAMBDA=lambda v: v == 'ZZZ' | ||
|
||
@classmethod | ||
def total_steps(cls, instructions, nodes, node_key=NODE_KEY, match_lambda=MATCH_LAMBDA): | ||
''' | ||
get total steps from walking instructions and nodes | ||
using node_key as initial starting node | ||
and end when node name matches with match_lambda | ||
''' | ||
total_steps=0 | ||
|
||
while True: | ||
for i in range(len(instructions)): | ||
total_steps += 1 | ||
instruction = instructions[i] | ||
current_node = nodes[node_key] | ||
|
||
if instruction == 'L': | ||
node_key = current_node[0] | ||
else: | ||
node_key = current_node[1] | ||
|
||
if match_lambda(node_key): | ||
return total_steps | ||
|
||
class Part2: | ||
MATCH_LAMBDA=lambda v: v.endswith('Z') | ||
|
||
@classmethod | ||
def get_node_keys(cls, nodes): | ||
return [x for x in nodes.keys() if x.endswith('A')] | ||
|
||
@classmethod | ||
def total_steps(cls, instructions, nodes, node_keys, match_lambda=MATCH_LAMBDA): | ||
min_steps_per_node_key = [Part1.total_steps(instructions, nodes, node_key, match_lambda) for node_key in node_keys] | ||
|
||
import math | ||
return math.lcm(*min_steps_per_node_key) |
Oops, something went wrong.