File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
src/main/java/com/adventofcode/flashk/day19 Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,22 @@ public Workflow(String input) {
2727 String rulesString = StringUtils .substringBetween (input , "{" , "}" );
2828 String [] rulesArray = rulesString .split ("," );
2929 rules = Arrays .stream (rulesArray ).map (Rule ::new ).collect (Collectors .toList ());
30+
31+ // TODO minor improvement
32+ // some workflows lead always to the same output workflow, in that case
33+ // rules can be directely bypassed.
34+ boolean sameWorkflows = true ;
35+ String workflowName = rules .get (0 ).getDestinationWorkflow ();
36+ for (Rule rule : rules ) {
37+ if (!rule .getDestinationWorkflow ().equals (workflowName )) {
38+ sameWorkflows = false ;
39+ }
40+ }
41+
42+ if (sameWorkflows ) {
43+ rules .clear ();
44+ rules .add (new Rule (workflowName ));
45+ }
3046 }
3147
3248 public String run (Part part ) {
You can’t perform that action at this time.
0 commit comments