Day 12 clippy lint.
This commit is contained in:
parent
b542304187
commit
e93f6d01ca
@ -1,24 +1,7 @@
|
|||||||
use std::{
|
use std::collections::HashMap;
|
||||||
collections::HashMap,
|
|
||||||
fmt::{Debug, Error, Formatter},
|
|
||||||
num::ParseIntError,
|
|
||||||
ops::{Index, IndexMut},
|
|
||||||
str::FromStr,
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use aoc_runner_derive::{aoc, aoc_generator};
|
use aoc_runner_derive::aoc;
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
struct Node {
|
|
||||||
name: String,
|
|
||||||
small: bool,
|
|
||||||
neighbors: Vec<usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Graph {
|
|
||||||
nodes: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn search(node: &str, nodes: &HashMap<&str, Vec<&str>>, path: String, paths: &mut Vec<String>) {
|
fn search(node: &str, nodes: &HashMap<&str, Vec<&str>>, path: String, paths: &mut Vec<String>) {
|
||||||
if node == "end" {
|
if node == "end" {
|
||||||
@ -27,10 +10,8 @@ fn search(node: &str, nodes: &HashMap<&str, Vec<&str>>, path: String, paths: &mu
|
|||||||
}
|
}
|
||||||
for neighbor in &nodes[node] {
|
for neighbor in &nodes[node] {
|
||||||
// If lowercase.
|
// If lowercase.
|
||||||
if neighbor.as_bytes()[0] & 0x20 != 0 {
|
if neighbor.as_bytes()[0] & 0x20 != 0 && path.contains(neighbor) {
|
||||||
if path.contains(neighbor) {
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
search(neighbor, nodes, format!("{},{}", path, neighbor), paths);
|
search(neighbor, nodes, format!("{},{}", path, neighbor), paths);
|
||||||
}
|
}
|
||||||
@ -47,8 +28,8 @@ fn part1(input: &str) -> Result<usize> {
|
|||||||
let mut nodes = HashMap::new();
|
let mut nodes = HashMap::new();
|
||||||
input.lines().for_each(|p| {
|
input.lines().for_each(|p| {
|
||||||
let (n1, n2) = p.split_once('-').expect("missing dash");
|
let (n1, n2) = p.split_once('-').expect("missing dash");
|
||||||
nodes.entry(n1).or_insert(Vec::new()).push(n2);
|
nodes.entry(n1).or_insert_with(Vec::new).push(n2);
|
||||||
nodes.entry(n2).or_insert(Vec::new()).push(n1);
|
nodes.entry(n2).or_insert_with(Vec::new).push(n1);
|
||||||
});
|
});
|
||||||
Ok(paths(&nodes))
|
Ok(paths(&nodes))
|
||||||
}
|
}
|
||||||
@ -98,7 +79,7 @@ fn paths2(nodes: &HashMap<&str, Vec<&str>>) -> usize {
|
|||||||
search2(
|
search2(
|
||||||
"start",
|
"start",
|
||||||
nodes,
|
nodes,
|
||||||
&vec!["start"],
|
&["start"],
|
||||||
&mut paths,
|
&mut paths,
|
||||||
double,
|
double,
|
||||||
smalls.as_slice(),
|
smalls.as_slice(),
|
||||||
@ -114,8 +95,8 @@ fn part2(input: &str) -> Result<usize> {
|
|||||||
let mut nodes = HashMap::new();
|
let mut nodes = HashMap::new();
|
||||||
input.lines().for_each(|p| {
|
input.lines().for_each(|p| {
|
||||||
let (n1, n2) = p.split_once('-').expect("missing dash");
|
let (n1, n2) = p.split_once('-').expect("missing dash");
|
||||||
nodes.entry(n1).or_insert(Vec::new()).push(n2);
|
nodes.entry(n1).or_insert_with(Vec::new).push(n2);
|
||||||
nodes.entry(n2).or_insert(Vec::new()).push(n1);
|
nodes.entry(n2).or_insert_with(Vec::new).push(n1);
|
||||||
});
|
});
|
||||||
Ok(paths2(&nodes))
|
Ok(paths2(&nodes))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user