Skip to content
Snippets Groups Projects
Commit 205adcbd authored by Evy Storozhenko's avatar Evy Storozhenko
Browse files

remove unused old code

parent 2fd18032
No related branches found
No related tags found
No related merge requests found
......@@ -5,86 +5,6 @@ mod matrix;
use matrix::Matrix;
use std::fs::read_to_string;
#[allow(unused)]
fn solve_without_types() {
let data = read_to_string("data.txt").unwrap();
let width = data.lines().next().unwrap().len();
let height = data.lines().count();
let mut vismap = Vec::<Vec<bool>>::new();
vismap.resize(height, {
let mut vec = Vec::new();
vec.resize(width, false);
vec
});
data.lines().zip(vismap.iter_mut()).for_each(|v| {
let mut smallest: i32 = -1;
v.0.chars()
.filter_map(|c| c.to_digit(10))
.zip(v.1.iter_mut())
.for_each(|v| {
if smallest == -1 || v.0 as i32 > smallest {
smallest = v.0 as i32;
*v.1 = true;
}
});
smallest = -1;
v.0.chars()
.rev()
.filter_map(|c| c.to_digit(10))
.zip(v.1.iter_mut().rev())
.for_each(|v| {
if smallest == -1 || v.0 as i32 > smallest {
smallest = v.0 as i32;
*v.1 = true;
}
});
});
for i in 0..width {
let mut smallest = -1;
data.chars()
.filter(|v| v != &'\n')
.zip(vismap.iter_mut().flat_map(|v| v.iter_mut()))
.enumerate()
.filter_map(|v| if v.0 % width == i { Some(v.1) } else { None })
.map(|v| (v.0.to_digit(10).unwrap(), v.1))
.for_each(|v| {
if v.0 as i32 > smallest {
smallest = v.0 as i32;
*v.1 = true;
}
});
smallest = -1;
data.lines()
.rev()
.collect::<String>()
.chars()
.zip(vismap.iter_mut().rev().flat_map(|v| v.iter_mut()))
.enumerate()
.filter_map(|v| if v.0 % width == i { Some(v.1) } else { None })
.map(|v| (v.0.to_digit(10).unwrap(), v.1))
.for_each(|v| {
if v.0 as i32 > smallest {
smallest = v.0 as i32;
*v.1 = true;
}
});
}
vismap.iter().for_each(|v| {
v.iter()
.for_each(|c| print!("{}", if *c { 'A' } else { '_' }));
println!();
});
let trees = vismap
.iter()
.map(|v| v.iter().filter(|&&v| v).count())
.sum::<usize>();
println!("Trees: {trees}");
}
fn main() {
let data = read_to_string("data.txt").unwrap();
let mut datamat = Matrix::new_from_str(&data, |c| (c.to_digit(10).unwrap(), false));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment