Linter cleanup

This commit is contained in:
Sebastian 2021-12-11 14:28:26 +01:00
parent 983e9d3c6f
commit 4aadc0a459
7 changed files with 15 additions and 17 deletions

View File

@ -1,4 +1,3 @@
use std::collections::HashSet;
use std::error::Error;
use std::fs::File;
use std::io::{self, BufRead};

View File

@ -3,11 +3,11 @@ use std::fs::File;
use std::io::{self, BufRead};
use std::vec::Vec;
const word_len: usize = 12;
const WORD_LEN: usize = 12;
fn to_weights(line: String) -> Vec<i32> {
let mut result = zero_fill(word_len);
for i in 0..word_len {
let mut result = zero_fill(WORD_LEN);
for i in 0..WORD_LEN {
result[i] = match line.chars().nth(i) {
Some('1') => 1,
Some('0') => -1,
@ -32,7 +32,7 @@ fn weights_to_int(weights: &Vec<i32>) -> i32 {
let mut res = 0;
for i in 0..weights.len() {
if weights[i] > 0 {
res |= 1 << word_len - 1 - i;
res |= 1 << WORD_LEN - 1 - i;
}
}
res
@ -44,16 +44,16 @@ fn main() -> Result<(), Box<dyn Error>> {
let weights: Vec<Vec<i32>> = lines.map(|l| to_weights(l)).collect();
let bits: Vec<i32> = weights.iter().fold(zero_fill(word_len), sum_weights);
let bits: Vec<i32> = weights.iter().fold(zero_fill(WORD_LEN), sum_weights);
let mut gamma = 0;
let mut epsilon = 0;
for i in 0..bits.len() {
if bits[i] > 0 {
gamma |= 1 << word_len - 1 - i;
gamma |= 1 << WORD_LEN - 1 - i;
} else {
epsilon |= 1 << word_len - 1 - i;
epsilon |= 1 << WORD_LEN - 1 - i;
}
}
@ -75,7 +75,7 @@ fn main() -> Result<(), Box<dyn Error>> {
})
.collect();
selection_pos += 1;
oxy_bits = oxy_weights.iter().fold(zero_fill(word_len), sum_weights);
oxy_bits = oxy_weights.iter().fold(zero_fill(WORD_LEN), sum_weights);
}
println!("oxy_weights: {:?}", oxy_weights);
@ -92,7 +92,7 @@ fn main() -> Result<(), Box<dyn Error>> {
})
.collect();
selection_pos += 1;
co2_bits = co2_weights.iter().fold(zero_fill(word_len), sum_weights);
co2_bits = co2_weights.iter().fold(zero_fill(WORD_LEN), sum_weights);
}
println!("co2_weights: {:?}", co2_weights);

View File

@ -72,7 +72,7 @@ fn parse_line(line: String) -> Line {
fn main() -> Result<(), Box<dyn Error>> {
let file = File::open("inputs/day5.txt")?;
let mut lines: Vec<Line> = io::BufReader::new(file)
let lines: Vec<Line> = io::BufReader::new(file)
.lines()
.map(|l| parse_line(l.unwrap()))
.collect();

View File

@ -5,7 +5,7 @@ use std::vec::Vec;
fn main() -> Result<(), Box<dyn Error>> {
let file = File::open("inputs/day6.txt")?;
let mut fishes: Vec<u64> = io::BufReader::new(file)
let fishes: Vec<u64> = io::BufReader::new(file)
.lines()
.nth(0)
.unwrap()
@ -15,7 +15,6 @@ fn main() -> Result<(), Box<dyn Error>> {
.collect();
let mut answer1 = 0;
let mut answer2 = 0;
let mut population: Vec<u64> = Vec::new();
population.resize(9, 0);
@ -41,7 +40,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}
}
answer2 = population.iter().fold(0, |a, b| a + b);
let answer2 = population.iter().fold(0, |a, b| a + b);
println!("Answer1: {}", answer1);

View File

@ -5,7 +5,7 @@ use std::vec::Vec;
fn main() -> Result<(), Box<dyn Error>> {
let file = File::open("inputs/day7.txt")?;
let mut crabs: Vec<i64> = io::BufReader::new(file)
let crabs: Vec<i64> = io::BufReader::new(file)
.lines()
.nth(0)
.unwrap()

View File

@ -32,7 +32,7 @@ fn parse_input(line: String) -> Line {
fn main() -> Result<(), Box<dyn Error>> {
let file = File::open("inputs/day8.txt")?;
let mut lines: Vec<Line> = io::BufReader::new(file)
let lines: Vec<Line> = io::BufReader::new(file)
.lines()
.map(|l| parse_input(l.unwrap()))
.collect();

View File

@ -50,7 +50,7 @@ fn find_basin_size(x: i32, y: i32, visted: &mut HashSet<(i32, i32)>, map: &Vec<V
fn main() -> Result<(), Box<dyn Error>> {
let file = File::open("inputs/day9.txt")?;
let mut map: Vec<Vec<u32>> = io::BufReader::new(file)
let map: Vec<Vec<u32>> = io::BufReader::new(file)
.lines()
.map(|l| {
l.unwrap()