day11 part1
This commit is contained in:
parent
f9095fdf8f
commit
8a40f62cf6
7
day11/Cargo.lock
generated
Normal file
7
day11/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "day11"
|
||||
version = "0.1.0"
|
8
day11/Cargo.toml
Normal file
8
day11/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "day11"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
10
day11/input.txt
Normal file
10
day11/input.txt
Normal file
@ -0,0 +1,10 @@
|
||||
...#......
|
||||
.......#..
|
||||
#.........
|
||||
..........
|
||||
......#...
|
||||
.#........
|
||||
.........#
|
||||
..........
|
||||
.......#..
|
||||
#...#.....
|
55
day11/src/main.rs
Normal file
55
day11/src/main.rs
Normal file
@ -0,0 +1,55 @@
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
let input = fs::read_to_string("input.txt").unwrap();
|
||||
let input: Vec<_> = input.split('\n')
|
||||
.map(|x| x.chars().collect::<Vec<char>>())
|
||||
.collect();
|
||||
|
||||
let mut rotate: Vec<Vec<char>> = vec![];
|
||||
for j in 0..input[0].len() {
|
||||
let mut tmp: Vec<char> = vec![];
|
||||
for i in 0..input.len() {
|
||||
tmp.push(input[i][j]);
|
||||
}
|
||||
|
||||
if tmp.iter().all(|x| x == &'.') {
|
||||
rotate.push(tmp.clone());
|
||||
}
|
||||
rotate.push(tmp);
|
||||
}
|
||||
|
||||
|
||||
let mut expanded: Vec<Vec<char>> = vec![];
|
||||
for j in 0..rotate[0].len() {
|
||||
let mut tmp: Vec<char> = vec![];
|
||||
for i in 0..rotate.len() {
|
||||
tmp.push(rotate[i][j]);
|
||||
}
|
||||
if tmp.iter().all(|x| x == &'.') {
|
||||
expanded.push(tmp.clone());
|
||||
}
|
||||
expanded.push(tmp);
|
||||
}
|
||||
|
||||
let mut galaxies: Vec<(i32, i32)> = vec![];
|
||||
|
||||
for (i, line) in expanded.iter().enumerate() {
|
||||
for (j, char) in line.iter().enumerate() {
|
||||
if char == &'#' {
|
||||
galaxies.push((i as i32,j as i32));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let dist_total = galaxies.clone().into_iter().enumerate()
|
||||
.fold(0, |mut acc, (i, gal)| {
|
||||
for next in &galaxies[i + 1..] {
|
||||
acc += gal.0.abs_diff(next.0) + gal.1.abs_diff(next.1);
|
||||
}
|
||||
acc
|
||||
});
|
||||
|
||||
println!("{:?}", dist_total);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user