Skip to content

Commit

Permalink
Improve cell usage in day20b, add missing days to runner
Browse files Browse the repository at this point in the history
  • Loading branch information
timvisee committed Jan 17, 2021
1 parent bf8a440 commit 74327e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions day20b/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
#![feature(array_windows, custom_inner_attributes, drain_filter, iterator_fold_self, str_split_once)]
#![rustfmt::skip]

use std::cell::Cell;
use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use std::mem;

Expand Down Expand Up @@ -219,12 219,12 @@ fn rot<T: Copy>(arr: &mut Vec<Vec<T>>, rot: usize) {
}

fn monsters(map: &mut Vec<Vec<bool>>) -> usize {
let count = Cell::new(0);
let count = RefCell::new(0);
map.iter()
.skip(1)
.enumerate()
.take(map.len() - 2)
.take_while(|(i, _)| *i < 3 || count.get() > 0)
.take_while(|(i, _)| *i < 3 || *count.borrow() > 0)
.map(|(y, row)| {
row.array_windows()
.skip(17)
Expand All @@ -234,6 234,6 @@ fn monsters(map: &mut Vec<Vec<bool>>) -> usize {
})
.count()
})
.for_each(|n| count.set(count.get() n));
count.get()
.for_each(|n| *count.borrow_mut() = n);
count.into_inner()
}
5 changes: 4 additions & 1 deletion runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 52,11 @@ pub fn jobs() -> &'static [fn()] {
fn_day!(day17b, "../../day17b/src/main.rs"),
fn_day!(day18a, "../../day18a/src/main.rs"),
fn_day!(day18b, "../../day18b/src/main.rs"),
// TODO: 19
fn_day!(day19a, "../../day19a/src/main.rs"),
fn_day!(day19b, "../../day19b/src/main.rs"),
fn_day!(day20a, "../../day20a/src/main.rs"),
fn_day!(day20b, "../../day20b/src/main.rs"),
fn_day!(day21a, "../../day21a/src/main.rs"),
fn_day!(day21b, "../../day21b/src/main.rs"),
]
}

0 comments on commit 74327e2

Please sign in to comment.