Pedantic clippy
This commit is contained in:
parent
fd608ac482
commit
68a50dab6e
@ -53,7 +53,7 @@ impl Tokenizer {
|
|||||||
|
|
||||||
fn score(self) -> Option<u64> {
|
fn score(self) -> Option<u64> {
|
||||||
self.stack.map(|stack| {
|
self.stack.map(|stack| {
|
||||||
stack.iter().rev().fold(0u64, |acc, c| {
|
stack.iter().rev().fold(0_u64, |acc, c| {
|
||||||
acc * 5
|
acc * 5
|
||||||
+ match c {
|
+ match c {
|
||||||
'(' => 1,
|
'(' => 1,
|
||||||
|
12
src/day11.rs
12
src/day11.rs
@ -4,26 +4,26 @@ fn square(x: usize, y: usize) -> Vec<(usize, usize)> {
|
|||||||
let mut sq = Vec::new();
|
let mut sq = Vec::new();
|
||||||
if y > 0 {
|
if y > 0 {
|
||||||
if x > 0 {
|
if x > 0 {
|
||||||
sq.push((x - 1, y - 1))
|
sq.push((x - 1, y - 1));
|
||||||
}
|
}
|
||||||
sq.push((x, y - 1));
|
sq.push((x, y - 1));
|
||||||
if x < 9 {
|
if x < 9 {
|
||||||
sq.push((x + 1, y - 1))
|
sq.push((x + 1, y - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if x > 0 {
|
if x > 0 {
|
||||||
sq.push((x - 1, y))
|
sq.push((x - 1, y));
|
||||||
}
|
}
|
||||||
if x < 9 {
|
if x < 9 {
|
||||||
sq.push((x + 1, y))
|
sq.push((x + 1, y));
|
||||||
}
|
}
|
||||||
if y < 9 {
|
if y < 9 {
|
||||||
if x > 0 {
|
if x > 0 {
|
||||||
sq.push((x - 1, y + 1))
|
sq.push((x - 1, y + 1));
|
||||||
}
|
}
|
||||||
sq.push((x, y + 1));
|
sq.push((x, y + 1));
|
||||||
if x < 9 {
|
if x < 9 {
|
||||||
sq.push((x + 1, y + 1))
|
sq.push((x + 1, y + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sq
|
sq
|
||||||
|
@ -54,14 +54,14 @@ fn main() {
|
|||||||
.collect::<Vec<FoldInstruction>>();
|
.collect::<Vec<FoldInstruction>>();
|
||||||
|
|
||||||
let mut all_dots: HashSet<(usize, usize)> = HashSet::new();
|
let mut all_dots: HashSet<(usize, usize)> = HashSet::new();
|
||||||
for dot in dots.iter() {
|
for dot in &dots {
|
||||||
all_dots.insert(instructions[0].wrap(*dot));
|
all_dots.insert(instructions[0].wrap(*dot));
|
||||||
}
|
}
|
||||||
println!("solution {}", all_dots.len());
|
println!("solution {}", all_dots.len());
|
||||||
|
|
||||||
all_dots.drain();
|
all_dots.drain();
|
||||||
for instr in instructions {
|
for instr in instructions {
|
||||||
for dot in dots.iter() {
|
for dot in &dots {
|
||||||
all_dots.insert(instr.wrap(*dot));
|
all_dots.insert(instr.wrap(*dot));
|
||||||
}
|
}
|
||||||
dots = all_dots.drain().collect();
|
dots = all_dots.drain().collect();
|
||||||
|
@ -15,7 +15,7 @@ fn polymerize(depth: usize, template: &str, rules: &[(char, char, char)]) -> (us
|
|||||||
|
|
||||||
for _ in 0..depth {
|
for _ in 0..depth {
|
||||||
let mut p = pairs.clone();
|
let mut p = pairs.clone();
|
||||||
for (pair, n) in pairs.iter() {
|
for (pair, n) in &pairs {
|
||||||
if let Some(rule) = rules
|
if let Some(rule) = rules
|
||||||
.iter()
|
.iter()
|
||||||
.find(|rule| rule.0 == pair.0 && rule.1 == pair.1)
|
.find(|rule| rule.0 == pair.0 && rule.1 == pair.1)
|
||||||
|
@ -96,10 +96,10 @@ impl RiskMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_map(risk_map: Vec<Vec<u32>>) -> Vec<Vec<u32>> {
|
fn expand_map(risk_map: &[Vec<u32>]) -> Vec<Vec<u32>> {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
for i in 0..5 {
|
for i in 0..5 {
|
||||||
for row in risk_map.iter() {
|
for row in risk_map {
|
||||||
let rows = [
|
let rows = [
|
||||||
row.iter()
|
row.iter()
|
||||||
.map(|x| (x + i - 1) % 9 + 1)
|
.map(|x| (x + i - 1) % 9 + 1)
|
||||||
@ -128,7 +128,7 @@ fn main() {
|
|||||||
.lines()
|
.lines()
|
||||||
.map(|line| line.chars().map(|c| c.to_digit(10).unwrap()).collect())
|
.map(|line| line.chars().map(|c| c.to_digit(10).unwrap()).collect())
|
||||||
.collect::<Vec<Vec<u32>>>();
|
.collect::<Vec<Vec<u32>>>();
|
||||||
let mut risk_map = RiskMap::new(expand_map(risk_level));
|
let mut risk_map = RiskMap::new(expand_map(&risk_level));
|
||||||
println!("solution {}", risk_map.shortest_path().unwrap());
|
println!("solution {}", risk_map.shortest_path().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +168,6 @@ fn test_expand_map() {
|
|||||||
.lines()
|
.lines()
|
||||||
.map(|line| line.chars().map(|c| c.to_digit(10).unwrap()).collect())
|
.map(|line| line.chars().map(|c| c.to_digit(10).unwrap()).collect())
|
||||||
.collect::<Vec<Vec<u32>>>();
|
.collect::<Vec<Vec<u32>>>();
|
||||||
let mut risk_map = RiskMap::new(expand_map(risk_level));
|
let mut risk_map = RiskMap::new(expand_map(&risk_level));
|
||||||
assert_eq!(risk_map.shortest_path().unwrap(), 315);
|
assert_eq!(risk_map.shortest_path().unwrap(), 315);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ struct Board {
|
|||||||
|
|
||||||
impl Board {
|
impl Board {
|
||||||
fn mark(&mut self, number: u8) {
|
fn mark(&mut self, number: u8) {
|
||||||
for row in self.grid.iter_mut() {
|
for row in &mut self.grid {
|
||||||
if let Some(square) = row.iter_mut().find(|square| square.number == number) {
|
if let Some(square) = row.iter_mut().find(|square| square.number == number) {
|
||||||
square.marked = true;
|
square.marked = true;
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ impl Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_winning(&self) -> bool {
|
fn is_winning(&self) -> bool {
|
||||||
for row in self.grid.iter() {
|
for row in &self.grid {
|
||||||
if row.iter().all(|s| s.marked) {
|
if row.iter().all(|s| s.marked) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ impl Board {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn score(&self) -> u32 {
|
fn score(&self) -> u32 {
|
||||||
self.grid.iter().fold(0u32, |acc, row| {
|
self.grid.iter().fold(0_u32, |acc, row| {
|
||||||
acc + row
|
acc + row
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| if s.marked { 0 } else { s.number as u32 })
|
.map(|s| if s.marked { 0 } else { s.number as u32 })
|
||||||
@ -78,7 +78,7 @@ fn solve_part1(input: &str) {
|
|||||||
let mut boards: Vec<Board> = blocks.map(|b| b.parse().unwrap()).collect();
|
let mut boards: Vec<Board> = blocks.map(|b| b.parse().unwrap()).collect();
|
||||||
|
|
||||||
for number in drawn_numbers {
|
for number in drawn_numbers {
|
||||||
for board in boards.iter_mut() {
|
for board in &mut boards {
|
||||||
board.mark(number);
|
board.mark(number);
|
||||||
if board.is_winning() {
|
if board.is_winning() {
|
||||||
println!(
|
println!(
|
||||||
|
@ -14,8 +14,8 @@ const BIRTH_RATE: usize = 7;
|
|||||||
const MATURITY: usize = 9;
|
const MATURITY: usize = 9;
|
||||||
|
|
||||||
fn solve(fishes: Vec<usize>, days: usize) -> u64 {
|
fn solve(fishes: Vec<usize>, days: usize) -> u64 {
|
||||||
let mut timers = [0u64; BIRTH_RATE];
|
let mut timers = [0_u64; BIRTH_RATE];
|
||||||
let mut new_timers = [0u64; MATURITY];
|
let mut new_timers = [0_u64; MATURITY];
|
||||||
|
|
||||||
for fish in fishes {
|
for fish in fishes {
|
||||||
timers[fish] += 1;
|
timers[fish] += 1;
|
||||||
|
@ -56,7 +56,7 @@ fn decode(patterns: Vec<&str>, outputs: Vec<&str>) -> u32 {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<u32>>();
|
.collect::<Vec<u32>>();
|
||||||
|
|
||||||
let mut iter = outputs.iter();
|
let mut iter = outputs.into_iter();
|
||||||
decode_digit(&patterns, digit_positions.iter(), iter.next().unwrap()) * 1000
|
decode_digit(&patterns, digit_positions.iter(), iter.next().unwrap()) * 1000
|
||||||
+ decode_digit(&patterns, digit_positions.iter(), iter.next().unwrap()) * 100
|
+ decode_digit(&patterns, digit_positions.iter(), iter.next().unwrap()) * 100
|
||||||
+ decode_digit(&patterns, digit_positions.iter(), iter.next().unwrap()) * 10
|
+ decode_digit(&patterns, digit_positions.iter(), iter.next().unwrap()) * 10
|
||||||
|
@ -17,16 +17,16 @@ fn main() {
|
|||||||
fn neighbors(x: usize, y: usize, row: &[u32], map: &[Vec<u32>]) -> Vec<u32> {
|
fn neighbors(x: usize, y: usize, row: &[u32], map: &[Vec<u32>]) -> Vec<u32> {
|
||||||
let mut neighbors = Vec::new();
|
let mut neighbors = Vec::new();
|
||||||
if x > 0 {
|
if x > 0 {
|
||||||
neighbors.push(row[x - 1])
|
neighbors.push(row[x - 1]);
|
||||||
}
|
}
|
||||||
if x < row.len() - 1 {
|
if x < row.len() - 1 {
|
||||||
neighbors.push(row[x + 1])
|
neighbors.push(row[x + 1]);
|
||||||
}
|
}
|
||||||
if y > 0 {
|
if y > 0 {
|
||||||
neighbors.push(map[y - 1][x])
|
neighbors.push(map[y - 1][x]);
|
||||||
}
|
}
|
||||||
if y < map.len() - 1 {
|
if y < map.len() - 1 {
|
||||||
neighbors.push(map[y + 1][x])
|
neighbors.push(map[y + 1][x]);
|
||||||
}
|
}
|
||||||
neighbors
|
neighbors
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user