[rs] Clean up 2022_09
This commit is contained in:
parent
55c8b96c68
commit
89365ca600
1 changed files with 0 additions and 37 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::iter;
|
|
||||||
|
|
||||||
fn simulate_rope(input: &str, segments: usize) -> usize {
|
fn simulate_rope(input: &str, segments: usize) -> usize {
|
||||||
let mut head = (0_i32, 0_i32);
|
let mut head = (0_i32, 0_i32);
|
||||||
|
|
@ -35,39 +34,3 @@ pub fn solve(input: String) {
|
||||||
println!("Part 1: {}", simulate_rope(&input, 2));
|
println!("Part 1: {}", simulate_rope(&input, 2));
|
||||||
println!("Part 2: {}", simulate_rope(&input, 10));
|
println!("Part 2: {}", simulate_rope(&input, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eprint_field(head: (i32, i32), tails: &[(i32, i32)], trail: &HashSet<(i32, i32)>) {
|
|
||||||
let coords = iter::once((0, 0))
|
|
||||||
.chain(iter::once(head))
|
|
||||||
.chain(tails.iter().cloned())
|
|
||||||
.chain(trail.iter().cloned())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let min_x = *coords.iter().map(|(x, _)| x).min().unwrap();
|
|
||||||
let max_x = *coords.iter().map(|(x, _)| x).max().unwrap();
|
|
||||||
let min_y = *coords.iter().map(|(_, y)| y).min().unwrap();
|
|
||||||
let max_y = *coords.iter().map(|(_, y)| y).max().unwrap();
|
|
||||||
let width = (max_x - min_x + 1) as usize;
|
|
||||||
let height = (max_y - min_y + 1) as usize;
|
|
||||||
let mut field = vec![vec!['.'; width]; height];
|
|
||||||
let set = |field: &mut [Vec<char>], x: i32, y: i32, c: char| {
|
|
||||||
field[(y - min_y) as usize][(x - min_x) as usize] = c;
|
|
||||||
};
|
|
||||||
for (x, y) in trail.iter() {
|
|
||||||
set(&mut field, *x, *y, '#');
|
|
||||||
}
|
|
||||||
set(&mut field, 0, 0, 's');
|
|
||||||
for (i, (x, y)) in tails.iter().enumerate().rev() {
|
|
||||||
set(&mut field, *x, *y, (('1' as usize) + i) as u8 as char);
|
|
||||||
}
|
|
||||||
set(&mut field, head.0, head.1, 'H');
|
|
||||||
for row in field.into_iter().rev() {
|
|
||||||
eprintln!(
|
|
||||||
"{}",
|
|
||||||
row.iter()
|
|
||||||
.map(|c| format!("{c}"))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join("")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
eprintln!();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue