day 6 testing
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
blackbeard420 2021-12-08 23:55:36 -05:00
parent 2c413315ad
commit 773fdbf91f
Signed by: blackbeard420
GPG Key ID: 88C719E09CDDA4A5
3 changed files with 72 additions and 0 deletions

7
rust/day6/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 = "day6"
version = "0.1.0"

8
rust/day6/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day6"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

57
rust/day6/src/main.rs Normal file
View File

@ -0,0 +1,57 @@
use std::fs;
use std::io::BufRead;
static PATH: &'static str = "../../inputs/input-day6";
fn remove_whitespace(s: &str) -> String {
return s.split_whitespace().collect();
}
fn load_file() -> Result<Vec<i64>, std::io::Error> {
let file = fs::File::open(PATH)?;
let reader = std::io::BufReader::new(file);
let res: Vec<i64> = reader.split(b',').map(|p| {
let p = p.unwrap();
let v = String::from_utf8_lossy(&p);
return remove_whitespace(&v).parse::<i64>().unwrap();
}).collect();
return Ok(res);
}
fn run_day(v: &mut Vec<i64>) {
let len = v.len();
for i in 0..len {
if v[i] == 0 {
v[i] = 6;
v.push(8);
} else {
v[i] -= 1;
}
}
}
fn part1() {
let mut x = load_file().unwrap();
for _ in 0..80 {
run_day(&mut x);
}
println!("total: {}", x.len());
}
fn part2() {
let mut x = load_file().unwrap();
for _ in 0..256 {
run_day(&mut x);
}
println!("total: {}", x.len());
}
fn main() {
part1();
part2();
}