This commit is contained in:
Dory 2024-06-16 23:12:11 -07:00
parent 1affc44c28
commit 5d522dc0f6
5 changed files with 2145 additions and 0 deletions

7
day18/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day17"
version = "0.1.0"

6
day18/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "day17"
version = "0.1.0"
edition = "2021"
[dependencies]

2085
day18/input.txt Normal file

File diff suppressed because it is too large Load Diff

34
day18/src/main.rs Normal file
View File

@ -0,0 +1,34 @@
use std::io;
use std::env;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::collections::HashSet;
fn main() -> io::Result<()> {
let input_fname = env::args().nth(1).expect("need input file");
let lines = BufReader::new(File::open(input_fname)?).lines();
let mut cubes: HashSet<(i8, i8, i8)> = HashSet::new();
for line in lines.flatten() {
let mut split = line.split(',');
let x = split.next().unwrap().to_string().parse::<i8>().unwrap();
let y = split.next().unwrap().to_string().parse::<i8>().unwrap();
let z = split.next().unwrap().to_string().parse::<i8>().unwrap();
cubes.insert((x, y, z));
}
let mut all_neighbors = 0;
for (x, y, z) in &cubes {
let neighbors = HashSet::from([
(*x + 1, *y, *z), (*x - 1, *y, *z),
(*x, *y + 1, *z), (*x, *y - 1, *z),
(*x, *y, *z + 1), (*x, *y, *z - 1)
]);
all_neighbors += cubes.intersection(&neighbors).count();
}
println!("{}", cubes.len() * 6 - all_neighbors);
Ok(())
}

13
day18/test.txt Normal file
View File

@ -0,0 +1,13 @@
2,2,2
1,2,2
3,2,2
2,1,2
2,3,2
2,2,1
2,2,3
2,2,4
2,2,6
1,2,5
3,2,5
2,1,5
2,3,5