Skip to content

Commit

Permalink
aoc; day 2021.25
Browse files Browse the repository at this point in the history
  • Loading branch information
skanev committed Dec 25, 2021
1 parent ad6b445 commit d04ead6
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 0 deletions.
8 changes: 8 additions & 0 deletions advent-of-code/2021/day25/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "day25"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
55 changes: 55 additions & 0 deletions advent-of-code/2021/day25/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::fs;

fn main() {
let mut map: Vec<Vec<u8>> = fs::read_to_string("../inputs/25")
.unwrap()
.lines()
.map(|line| line.bytes().collect())
.collect();

let mut steps = 0;
let h = map.len();
let w = map[0].len();

loop {
steps += 1;

let mut horizontal = vec![];

for x in 0..h {
for y in 0..w {
let adjancent = (y + 1) % w;
if map[x][y] == b'>' && map[x][adjancent] == b'.' {
horizontal.push((x, y, adjancent));
}
}
}

for &(x, y, a) in &horizontal {
map[x][y] = b'.';
map[x][a] = b'>';
}

let mut vertical = vec![];

for x in 0..h {
for y in 0..w {
let adjancent = (x + 1) % h;
if map[x][y] == b'v' && map[adjancent][y] == b'.' {
vertical.push((x, y, adjancent));
}
}
}

for &(x, y, a) in &vertical {
map[x][y] = b'.';
map[a][y] = b'v';
}

if vertical.is_empty() && horizontal.is_empty() {
break;
}
}

println!("final = {}", steps);
}

0 comments on commit d04ead6

Please sign in to comment.