From 4aadc0a4593c44ac939ac598124146c2e1c1a640 Mon Sep 17 00:00:00 2001 From: LongHairedHacker Date: Sat, 11 Dec 2021 14:28:26 +0100 Subject: [PATCH] Linter cleanup --- src/bin/day10.rs | 1 - src/bin/day3.rs | 18 +++++++++--------- src/bin/day5.rs | 2 +- src/bin/day6.rs | 5 ++--- src/bin/day7.rs | 2 +- src/bin/day8.rs | 2 +- src/bin/day9.rs | 2 +- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/bin/day10.rs b/src/bin/day10.rs index 55da77a..ba2e8d0 100644 --- a/src/bin/day10.rs +++ b/src/bin/day10.rs @@ -1,4 +1,3 @@ -use std::collections::HashSet; use std::error::Error; use std::fs::File; use std::io::{self, BufRead}; diff --git a/src/bin/day3.rs b/src/bin/day3.rs index b1908ca..aa2ff2f 100644 --- a/src/bin/day3.rs +++ b/src/bin/day3.rs @@ -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 { - 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 { 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> { let weights: Vec> = lines.map(|l| to_weights(l)).collect(); - let bits: Vec = weights.iter().fold(zero_fill(word_len), sum_weights); + let bits: Vec = 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> { }) .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> { }) .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); diff --git a/src/bin/day5.rs b/src/bin/day5.rs index 7e920e5..fcc01c7 100644 --- a/src/bin/day5.rs +++ b/src/bin/day5.rs @@ -72,7 +72,7 @@ fn parse_line(line: String) -> Line { fn main() -> Result<(), Box> { let file = File::open("inputs/day5.txt")?; - let mut lines: Vec = io::BufReader::new(file) + let lines: Vec = io::BufReader::new(file) .lines() .map(|l| parse_line(l.unwrap())) .collect(); diff --git a/src/bin/day6.rs b/src/bin/day6.rs index c2ab31d..6510a9d 100644 --- a/src/bin/day6.rs +++ b/src/bin/day6.rs @@ -5,7 +5,7 @@ use std::vec::Vec; fn main() -> Result<(), Box> { let file = File::open("inputs/day6.txt")?; - let mut fishes: Vec = io::BufReader::new(file) + let fishes: Vec = io::BufReader::new(file) .lines() .nth(0) .unwrap() @@ -15,7 +15,6 @@ fn main() -> Result<(), Box> { .collect(); let mut answer1 = 0; - let mut answer2 = 0; let mut population: Vec = Vec::new(); population.resize(9, 0); @@ -41,7 +40,7 @@ fn main() -> Result<(), Box> { } } - answer2 = population.iter().fold(0, |a, b| a + b); + let answer2 = population.iter().fold(0, |a, b| a + b); println!("Answer1: {}", answer1); diff --git a/src/bin/day7.rs b/src/bin/day7.rs index 8959c46..9063340 100644 --- a/src/bin/day7.rs +++ b/src/bin/day7.rs @@ -5,7 +5,7 @@ use std::vec::Vec; fn main() -> Result<(), Box> { let file = File::open("inputs/day7.txt")?; - let mut crabs: Vec = io::BufReader::new(file) + let crabs: Vec = io::BufReader::new(file) .lines() .nth(0) .unwrap() diff --git a/src/bin/day8.rs b/src/bin/day8.rs index 19f49fc..61642a2 100644 --- a/src/bin/day8.rs +++ b/src/bin/day8.rs @@ -32,7 +32,7 @@ fn parse_input(line: String) -> Line { fn main() -> Result<(), Box> { let file = File::open("inputs/day8.txt")?; - let mut lines: Vec = io::BufReader::new(file) + let lines: Vec = io::BufReader::new(file) .lines() .map(|l| parse_input(l.unwrap())) .collect(); diff --git a/src/bin/day9.rs b/src/bin/day9.rs index b551b63..21c71f1 100644 --- a/src/bin/day9.rs +++ b/src/bin/day9.rs @@ -50,7 +50,7 @@ fn find_basin_size(x: i32, y: i32, visted: &mut HashSet<(i32, i32)>, map: &Vec Result<(), Box> { let file = File::open("inputs/day9.txt")?; - let mut map: Vec> = io::BufReader::new(file) + let map: Vec> = io::BufReader::new(file) .lines() .map(|l| { l.unwrap()