-
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
148123c
commit 478e9ad
Showing
6 changed files
with
999 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from enum import Enum | ||
from typing import List | ||
from data.day19 import Workflow, Parts | ||
|
||
|
||
class ResultLabel(Enum): | ||
ACCEPT = 'A' | ||
REJECT = 'R' | ||
|
||
|
||
def evaulate_next_workflow( | ||
parts: Parts, | ||
workflows: dict[Workflow], | ||
workflow_name: str = 'in', | ||
): | ||
expr = workflows.get(workflow_name).expressions_eval_str | ||
return eval(expr, parts.xmas) | ||
|
||
|
||
def check_parts_accepted( | ||
parts: Parts, | ||
workflows: dict[Workflow], | ||
workflow_name: str = 'in', | ||
verbose=False, | ||
): | ||
while workflow_name not in [ | ||
ResultLabel.ACCEPT.value, | ||
ResultLabel.REJECT.value, | ||
]: | ||
expr = workflows.get(workflow_name).expressions_eval_str | ||
if verbose: | ||
print(workflow_name, '\t\t', expr) | ||
workflow_name = eval(expr, parts.xmas) | ||
|
||
return workflow_name == ResultLabel.ACCEPT.value | ||
|
||
|
||
def get_sum_of_all_expected_parts( | ||
parts_list: List[Parts], | ||
workflows: dict[Workflow], | ||
workflow_name: str = 'in', | ||
verbose=False, | ||
): | ||
sum = 0 | ||
for parts in parts_list: | ||
if check_parts_accepted(parts, workflows, workflow_name, verbose): | ||
sum += parts.xmas['x'] + parts.xmas['m'] + parts.xmas['a'] + parts.xmas['s'] | ||
return sum |
Oops, something went wrong.