@@ -35,17 +35,7 @@ pub fn parse(input: &str) -> Input {
3535pub  fn  part1 ( input :  & Input )  -> String  { 
3636    // Move all steps with no dependencies to the `ready` map. A `BTreeMap` is sorted by key 
3737    // so will retrieve steps in alphabetical order. 
38-     let  mut  ready = BTreeMap :: new ( ) ; 
39-     let  mut  blocked = FastMap :: new ( ) ; 
40- 
41-     for  ( key,  step)  in  input. clone ( )  { 
42-         if  step. remaining  == 0  { 
43-             ready. insert ( key,  step) ; 
44-         }  else  { 
45-             blocked. insert ( key,  step) ; 
46-         } 
47-     } 
48- 
38+     let  ( mut  ready,  mut  blocked)  = split_by_readiness ( input) ; 
4939    let  mut  done = String :: new ( ) ; 
5040
5141    while  let  Some ( ( key,  step) )  = ready. pop_first ( )  { 
@@ -75,16 +65,7 @@ pub fn part2(input: &Input) -> u32 {
7565
7666pub  fn  part2_testable ( input :  & Input ,  max_workers :  usize ,  base_duration :  u32 )  -> u32  { 
7767    // Same as part one, move all tasks that are root nodes to the `ready` map. 
78-     let  mut  ready = BTreeMap :: new ( ) ; 
79-     let  mut  blocked = FastMap :: new ( ) ; 
80- 
81-     for  ( key,  step)  in  input. clone ( )  { 
82-         if  step. remaining  == 0  { 
83-             ready. insert ( key,  step) ; 
84-         }  else  { 
85-             blocked. insert ( key,  step) ; 
86-         } 
87-     } 
68+     let  ( mut  ready,  mut  blocked)  = split_by_readiness ( input) ; 
8869
8970    // Loop until there are no more steps available and all workers are idle. 
9071    let  mut  time = 0 ; 
@@ -123,3 +104,18 @@ pub fn part2_testable(input: &Input, max_workers: usize, base_duration: u32) ->
123104
124105    time
125106} 
107+ 
108+ fn  split_by_readiness ( input :  & Input )  -> ( BTreeMap < u8 ,  Step > ,  FastMap < u8 ,  Step > )  { 
109+     let  mut  ready = BTreeMap :: new ( ) ; 
110+     let  mut  blocked = FastMap :: new ( ) ; 
111+ 
112+     for  ( key,  step)  in  input. clone ( )  { 
113+         if  step. remaining  == 0  { 
114+             ready. insert ( key,  step) ; 
115+         }  else  { 
116+             blocked. insert ( key,  step) ; 
117+         } 
118+     } 
119+ 
120+     ( ready,  blocked) 
121+ } 
0 commit comments