adventofcode

git clone https://git.ce9e.org/adventofcode.git

commit
4014abd9f483824f746823514973eb85f3072fef
parent
e895158fae6d2249ae7af1d54998a82e8c682126
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2021-12-20 08:35
refactor

Diffstat

M 2021/20/part1.rs 26 ++++++++++++++++----------

1 files changed, 16 insertions, 10 deletions


diff --git a/2021/20/part1.rs b/2021/20/part1.rs

@@ -66,23 +66,29 @@ fn enhance(img: &Vec<Vec<bool>>, outside: bool, cypher: &Vec<bool>) -> (Vec<Vec<
   66    66     return (result, cypher[outside_i]);
   67    67 }
   68    68 
   -1    69 fn count(img: &Vec<Vec<bool>>) -> usize {
   -1    70     return img
   -1    71         .iter()
   -1    72         .map(|row| row
   -1    73             .iter()
   -1    74             .filter(|b| **b)
   -1    75             .count())
   -1    76         .sum();
   -1    77 }
   -1    78 
   69    79 fn main() {
   70    80     let (cypher, mut img) = get_data();
   71    81     let mut outside = false;
   72    82 
   73    -1     for _ in 0..50 {
   -1    83     for i in 0..50 {
   74    84         let data = enhance(&img, outside, &cypher);
   75    85         img = data.0;
   76    86         outside = data.1;
   77    -1     }
   78    87 
   79    -1     let count: usize = img
   80    -1         .iter()
   81    -1         .map(|row| row
   82    -1             .iter()
   83    -1             .filter(|b| **b)
   84    -1             .count())
   85    -1         .sum();
   -1    88         if i == 1 {
   -1    89             println!("{}", count(&img));
   -1    90         }
   -1    91     }
   86    92 
   87    -1     println!("{}", count);
   -1    93     println!("{}", count(&img));
   88    94 }