doing some clippy and testing gittea
This commit is contained in:
47
2024/Cargo.lock
generated
47
2024/Cargo.lock
generated
@@ -161,6 +161,47 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day-4"
|
||||||
|
version = "2024.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"dhat",
|
||||||
|
"error-stack",
|
||||||
|
"glam",
|
||||||
|
"itertools",
|
||||||
|
"log",
|
||||||
|
"nom",
|
||||||
|
"test-log",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day-5"
|
||||||
|
version = "2024.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"dhat",
|
||||||
|
"error-stack",
|
||||||
|
"itertools",
|
||||||
|
"log",
|
||||||
|
"nom",
|
||||||
|
"test-log",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "day-6"
|
||||||
|
version = "2024.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"dhat",
|
||||||
|
"error-stack",
|
||||||
|
"glam",
|
||||||
|
"itertools",
|
||||||
|
"log",
|
||||||
|
"nom",
|
||||||
|
"test-log",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dhat"
|
name = "dhat"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
@@ -321,6 +362,12 @@ version = "0.31.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
|
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glam"
|
||||||
|
version = "0.29.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc46dd3ec48fdd8e693a98d2b8bafae273a2d54c1de02a2a7e3d57d501f39677"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glob"
|
name = "glob"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ struct MyMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MyMap {
|
impl MyMap {
|
||||||
pub fn next_obstacle(&self, start_pos: &IVec2, direction: &Direction) -> Option<&IVec2> {
|
pub fn next_obstacle(&self, start_pos: IVec2, direction: &Direction) -> Option<&IVec2> {
|
||||||
self.obstacles
|
self.obstacles
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|obstacle| match direction {
|
.filter(|obstacle| match direction {
|
||||||
@@ -73,10 +73,10 @@ impl MyMap {
|
|||||||
Direction::West => obstacle.x == start_pos.x && obstacle.y < start_pos.y,
|
Direction::West => obstacle.x == start_pos.x && obstacle.y < start_pos.y,
|
||||||
})
|
})
|
||||||
.fold(None, |acc, obstacle| match direction {
|
.fold(None, |acc, obstacle| match direction {
|
||||||
Direction::North if acc == None || obstacle.x > acc.unwrap().x => Some(obstacle),
|
Direction::North if acc.is_none() || obstacle.x > acc.unwrap().x => Some(obstacle),
|
||||||
Direction::East if acc == None || obstacle.y < acc.unwrap().y => Some(obstacle),
|
Direction::East if acc.is_none() || obstacle.y < acc.unwrap().y => Some(obstacle),
|
||||||
Direction::South if acc == None || obstacle.x < acc.unwrap().x => Some(obstacle),
|
Direction::South if acc.is_none() || obstacle.x < acc.unwrap().x => Some(obstacle),
|
||||||
Direction::West if acc == None || obstacle.y > acc.unwrap().y => Some(obstacle),
|
Direction::West if acc.is_none() || obstacle.y > acc.unwrap().y => Some(obstacle),
|
||||||
_ => acc,
|
_ => acc,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -87,6 +87,9 @@ impl MyMap {
|
|||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// - `ParseError` there was an issue with the parser
|
/// - `ParseError` there was an issue with the parser
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
/// - it just does
|
||||||
pub fn part1(input: &str) -> Result<String, Day6Part1Error> {
|
pub fn part1(input: &str) -> Result<String, Day6Part1Error> {
|
||||||
//let input = Span::new(input);
|
//let input = Span::new(input);
|
||||||
//TODO figure out how to real error
|
//TODO figure out how to real error
|
||||||
@@ -99,7 +102,7 @@ pub fn part1(input: &str) -> Result<String, Day6Part1Error> {
|
|||||||
&& (guard_pos.y as u32) < map.width
|
&& (guard_pos.y as u32) < map.width
|
||||||
{
|
{
|
||||||
let _ = visited.insert(guard_pos);
|
let _ = visited.insert(guard_pos);
|
||||||
if let Some(next_obstacle) = map.next_obstacle(&guard_pos, &guard_dir) {
|
if let Some(next_obstacle) = map.next_obstacle(guard_pos, &guard_dir) {
|
||||||
// println!("Hit row {}, col {} going {:?}", next_obstacle.x, next_obstacle.y, guard_dir);
|
// println!("Hit row {}, col {} going {:?}", next_obstacle.x, next_obstacle.y, guard_dir);
|
||||||
match guard_dir {
|
match guard_dir {
|
||||||
Direction::North => {
|
Direction::North => {
|
||||||
@@ -130,7 +133,7 @@ pub fn part1(input: &str) -> Result<String, Day6Part1Error> {
|
|||||||
visited.insert(x);
|
visited.insert(x);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
guard_pos = next_obstacle - &guard_dir;
|
guard_pos = next_obstacle - &guard_dir;
|
||||||
} else {
|
} else {
|
||||||
let new_pos = match guard_dir {
|
let new_pos = match guard_dir {
|
||||||
@@ -169,7 +172,7 @@ pub fn part1(input: &str) -> Result<String, Day6Part1Error> {
|
|||||||
visited.insert(x);
|
visited.insert(x);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
guard_pos = new_pos;
|
guard_pos = new_pos;
|
||||||
//break
|
//break
|
||||||
}
|
}
|
||||||
@@ -187,12 +190,25 @@ pub fn part1(input: &str) -> Result<String, Day6Part1Error> {
|
|||||||
print!("\n");
|
print!("\n");
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
for row in 0.. map.height.try_into().unwrap() {
|
||||||
|
for col in 0..map.width.try_into().unwrap() {
|
||||||
|
let pos = IVec2::new(row, col);
|
||||||
|
if visited.contains(&pos) {
|
||||||
|
print!("X");
|
||||||
|
}else if map.obstacles.contains(&pos) {
|
||||||
|
print!("#");
|
||||||
|
} else {
|
||||||
|
print!(".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
|
||||||
Ok(visited.iter().count().to_string())
|
Ok(visited.len().to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_input(input: &str) -> (IVec2, MyMap) {
|
fn parse_input(input: &str) -> (IVec2, MyMap) {
|
||||||
let (pos, height, width, obstacles) = input.lines().into_iter().enumerate().fold(
|
let (pos, height, width, obstacles) = input.lines().enumerate().fold(
|
||||||
(IVec2::ZERO, 0, 0, HashSet::new()),
|
(IVec2::ZERO, 0, 0, HashSet::new()),
|
||||||
|mut acc, (row_no, row)| {
|
|mut acc, (row_no, row)| {
|
||||||
acc.1 = row_no.try_into().unwrap();
|
acc.1 = row_no.try_into().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user