Add D11P2
This commit is contained in:
parent
0942f432ed
commit
7ce5013eb3
|
@ -28,16 +28,16 @@ fn turn(dir: Direction, turn_value: i64) -> Direction {
|
||||||
|
|
||||||
fn mv(pos: (i64, i64), dir: &Direction) -> (i64, i64) {
|
fn mv(pos: (i64, i64), dir: &Direction) -> (i64, i64) {
|
||||||
match dir {
|
match dir {
|
||||||
Direction::Up => (pos.0, pos.1 + 1),
|
Direction::Up => (pos.0, pos.1 + 1),
|
||||||
Direction::Right => (pos.0 + 1, pos.1),
|
Direction::Right => (pos.0 + 1, pos.1),
|
||||||
Direction::Left => (pos.0 - 1, pos.1),
|
Direction::Left => (pos.0 - 1, pos.1),
|
||||||
Direction::Down => (pos.0, pos.1 - 1),
|
Direction::Down => (pos.0, pos.1 - 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut positions= HashMap::new();
|
let mut positions = HashMap::new();
|
||||||
let mut pc = IntComputer::new(read_input(), 0, vec![0]);
|
let mut pc = IntComputer::new(read_input(), 0, vec![1]);
|
||||||
let mut pos = (0, 0);
|
let mut pos = (0, 0);
|
||||||
let mut direction = Direction::Up;
|
let mut direction = Direction::Up;
|
||||||
while let IntComputerResult::Output(o) = pc.run() {
|
while let IntComputerResult::Output(o) = pc.run() {
|
||||||
|
@ -47,5 +47,44 @@ fn main() {
|
||||||
pos = mv(pos, &direction);
|
pos = mv(pos, &direction);
|
||||||
pc.params.push(*positions.get(&pos).unwrap_or(&0));
|
pc.params.push(*positions.get(&pos).unwrap_or(&0));
|
||||||
}
|
}
|
||||||
|
//
|
||||||
println!("Part 1: {}", positions.len());
|
println!("Part 1: {}", positions.len());
|
||||||
|
let x_max = positions
|
||||||
|
.clone()
|
||||||
|
.keys()
|
||||||
|
.into_iter()
|
||||||
|
.max_by_key(|k| k.0)
|
||||||
|
.unwrap()
|
||||||
|
.0;
|
||||||
|
let y_max = positions
|
||||||
|
.clone()
|
||||||
|
.keys()
|
||||||
|
.into_iter()
|
||||||
|
.max_by_key(|k| k.1)
|
||||||
|
.unwrap()
|
||||||
|
.1;
|
||||||
|
let x_min = positions
|
||||||
|
.clone()
|
||||||
|
.keys()
|
||||||
|
.into_iter()
|
||||||
|
.min_by_key(|k| k.0)
|
||||||
|
.unwrap()
|
||||||
|
.0;
|
||||||
|
let y_min = positions
|
||||||
|
.clone()
|
||||||
|
.keys()
|
||||||
|
.into_iter()
|
||||||
|
.min_by_key(|k| k.1)
|
||||||
|
.unwrap()
|
||||||
|
.1;
|
||||||
|
for y in (y_min..y_max+1).rev() {
|
||||||
|
println!(
|
||||||
|
"{}",
|
||||||
|
(x_min..x_max)
|
||||||
|
.map(|x| positions.get(&(x, y)).unwrap_or(&0).to_string())
|
||||||
|
.collect::<String>()
|
||||||
|
.replace('0', " ")
|
||||||
|
.replace('1', "█")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user