1
0
mirror of https://gitlab.com/MisterBiggs/aoc2021.git synced 2025-07-27 08:21:22 +00:00

day3 part1

This commit is contained in:
2021-12-04 15:50:25 -07:00
parent 8dbc567784
commit 4f4ab5d900
3 changed files with 1051 additions and 0 deletions

1000
day3/input.txt Normal file

File diff suppressed because it is too large Load Diff

8
day3/rust/Cargo.toml Normal file

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

43
day3/rust/src/main.rs Normal file

@@ -0,0 +1,43 @@
use std::fs;
fn main() {
let input = fs::read_to_string("../input.txt").expect("Could not read file");
let report: Vec<&str> = input.lines().collect();
let bit_count = report[0].len();
let col_size = report.len();
let mut gamma = 0;
let mut epsilon = 0;
for position in 0..bit_count {
gamma <<= 1;
epsilon <<= 1;
let count = report
.iter()
.filter(|b| b.chars().nth(position).unwrap() == '1')
.count();
if count > col_size / 2 {
gamma += 1;
} else {
epsilon += 1;
}
}
println!("{}", gamma * epsilon);
// part1(input);
// part2(&commands);
}
// fn part1(report: String) {
// for i in 1..5 {
// let (ones, zeros): (Vec<&str>, Vec<&str>) =
// report.lines().partition(|l| l[i..l.len()].starts_with('1'));
// println!("{:?}", zeros);
// }
// }
// fn part2(commands: &Vec<(&str, i32)>) {
// todo!();
// }