refactor(lint): clippy
This commit is contained in:
parent
00000260bf
commit
00000270c2
|
@ -8,7 +8,7 @@ pub fn part_two(input: &str) -> Option<u32> {
|
||||||
match c {
|
match c {
|
||||||
'(' => floor += 1,
|
'(' => floor += 1,
|
||||||
')' => floor -= 1,
|
')' => floor -= 1,
|
||||||
_ => panic!("oops {}", c),
|
_ => panic!("oops {c}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
if floor < 0 {
|
if floor < 0 {
|
||||||
|
|
|
@ -14,7 +14,7 @@ fn allowed_password(password: &str) -> bool {
|
||||||
if password
|
if password
|
||||||
.chars()
|
.chars()
|
||||||
.tuple_windows()
|
.tuple_windows()
|
||||||
.map(|(a, b, c)| ASCII_LOWERCASE.contains(&format!("{}{}{}", a, b, c)))
|
.map(|(a, b, c)| ASCII_LOWERCASE.contains(&format!("{a}{b}{c}")))
|
||||||
.filter(|&y| y)
|
.filter(|&y| y)
|
||||||
.count()
|
.count()
|
||||||
== 0
|
== 0
|
||||||
|
@ -24,7 +24,7 @@ fn allowed_password(password: &str) -> bool {
|
||||||
|
|
||||||
if ASCII_LOWERCASE
|
if ASCII_LOWERCASE
|
||||||
.chars()
|
.chars()
|
||||||
.map(|a| password.contains(&format!("{}{}", a, a)))
|
.map(|a| password.contains(&format!("{a}{a}")))
|
||||||
.filter(|&y| y)
|
.filter(|&y| y)
|
||||||
.count()
|
.count()
|
||||||
< 2
|
< 2
|
||||||
|
@ -107,11 +107,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_one() {
|
fn test_part_one() {
|
||||||
let input = aoc::read_file("test_inputs", 11);
|
let input = aoc::read_file("test_inputs", 11);
|
||||||
assert_eq!(part_one(&input.trim()), Some("ghjaabcc".to_string()));
|
assert_eq!(part_one(input.trim()), Some("ghjaabcc".to_string()));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_two() {
|
fn test_part_two() {
|
||||||
let input = aoc::read_file("test_inputs", 11);
|
let input = aoc::read_file("test_inputs", 11);
|
||||||
assert_eq!(part_two(&input.trim()), Some("ghjbbcdd".to_string()));
|
assert_eq!(part_two(input.trim()), Some("ghjbbcdd".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_one() {
|
fn test_part_one() {
|
||||||
let input = aoc::read_file("test_inputs", 12);
|
let input = aoc::read_file("test_inputs", 12);
|
||||||
assert_eq!(part_one(&input.trim()), Some(15));
|
assert_eq!(part_one(input.trim()), Some(15));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_two() {
|
fn test_part_two() {
|
||||||
let input = aoc::read_file("test_inputs", 12);
|
let input = aoc::read_file("test_inputs", 12);
|
||||||
assert_eq!(part_two(&input.trim()), Some(0));
|
assert_eq!(part_two(input.trim()), Some(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,11 +87,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_one() {
|
fn test_part_one() {
|
||||||
let input = aoc::read_file("test_inputs", 13);
|
let input = aoc::read_file("test_inputs", 13);
|
||||||
assert_eq!(part_one(&input.trim()), Some(330));
|
assert_eq!(part_one(input.trim()), Some(330));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_two() {
|
fn test_part_two() {
|
||||||
let input = aoc::read_file("test_inputs", 13);
|
let input = aoc::read_file("test_inputs", 13);
|
||||||
assert_eq!(part_two(&input.trim()), Some(286));
|
assert_eq!(part_two(input.trim()), Some(286));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl From<&str> for Reindeer {
|
||||||
pub fn part_one(input: &str) -> Option<u32> {
|
pub fn part_one(input: &str) -> Option<u32> {
|
||||||
input
|
input
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map(|x| Reindeer::from(x))
|
.map(Reindeer::from)
|
||||||
.map(|y| {
|
.map(|y| {
|
||||||
((DISTANCE / y.cycle()) * y.duration
|
((DISTANCE / y.cycle()) * y.duration
|
||||||
+ vec![DISTANCE % y.cycle(), y.duration].iter().min().unwrap())
|
+ vec![DISTANCE % y.cycle(), y.duration].iter().min().unwrap())
|
||||||
|
@ -71,7 +71,7 @@ impl Scoreboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn part_two(input: &str) -> Option<u32> {
|
pub fn part_two(input: &str) -> Option<u32> {
|
||||||
let reindeers = input.split('\n').map(|x| Reindeer::from(x)).collect_vec();
|
let reindeers = input.split('\n').map(Reindeer::from).collect_vec();
|
||||||
let mut scoreboards = vec![Scoreboard::empty(); reindeers.len()];
|
let mut scoreboards = vec![Scoreboard::empty(); reindeers.len()];
|
||||||
|
|
||||||
for traveled in 0..DISTANCE {
|
for traveled in 0..DISTANCE {
|
||||||
|
@ -108,11 +108,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_one() {
|
fn test_part_one() {
|
||||||
let input = aoc::read_file("test_inputs", 14);
|
let input = aoc::read_file("test_inputs", 14);
|
||||||
assert_eq!(part_one(&input.trim()), Some(1120));
|
assert_eq!(part_one(input.trim()), Some(1120));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_two() {
|
fn test_part_two() {
|
||||||
let input = aoc::read_file("test_inputs", 14);
|
let input = aoc::read_file("test_inputs", 14);
|
||||||
assert_eq!(part_two(&input.trim()), None);
|
assert_eq!(part_two(input.trim()), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
let day_padded = format!("{:02}", day);
|
let day_padded = format!("{day:02}");
|
||||||
let token = env::var("TOKEN").expect("$TOKEN is not set");
|
let token = env::var("TOKEN").expect("$TOKEN is not set");
|
||||||
let year = env::var("YEAR")
|
let year = env::var("YEAR")
|
||||||
.expect("$YEAR is not set")
|
.expect("$YEAR is not set")
|
||||||
|
@ -21,7 +21,7 @@ fn main() {
|
||||||
.expect("$YEAR must be a number");
|
.expect("$YEAR must be a number");
|
||||||
|
|
||||||
let mut headers = header::HeaderMap::new();
|
let mut headers = header::HeaderMap::new();
|
||||||
let mut session_header = header::HeaderValue::from_str(format!("session={}", token).as_str())
|
let mut session_header = header::HeaderValue::from_str(format!("session={token}").as_str())
|
||||||
.expect("Error building cookie header");
|
.expect("Error building cookie header");
|
||||||
session_header.set_sensitive(true);
|
session_header.set_sensitive(true);
|
||||||
headers.insert(header::COOKIE, session_header);
|
headers.insert(header::COOKIE, session_header);
|
||||||
|
@ -29,15 +29,14 @@ fn main() {
|
||||||
let client = Client::builder().default_headers(headers).build().unwrap();
|
let client = Client::builder().default_headers(headers).build().unwrap();
|
||||||
let res = client
|
let res = client
|
||||||
.get(format!(
|
.get(format!(
|
||||||
"https://adventofcode.com/{}/day/{}/input",
|
"https://adventofcode.com/{year}/day/{day}/input"
|
||||||
year, day
|
|
||||||
))
|
))
|
||||||
.send()
|
.send()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.text()
|
.text()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let input_path = format!("src/inputs/{}.txt", day_padded);
|
let input_path = format!("src/inputs/{day_padded}.txt");
|
||||||
let mut file = match OpenOptions::new()
|
let mut file = match OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
|
@ -45,7 +44,7 @@ fn main() {
|
||||||
{
|
{
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to create module file: {}", e);
|
eprintln!("Failed to create module file: {e}");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -55,7 +54,7 @@ fn main() {
|
||||||
println!("Downloaded input file \"{}\"", &input_path);
|
println!("Downloaded input file \"{}\"", &input_path);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to write module contents: {}", e);
|
eprintln!("Failed to write module contents: {e}");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,16 +52,16 @@ fn main() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let day_padded = format!("{:02}", day);
|
let day_padded = format!("{day:02}");
|
||||||
|
|
||||||
let input_path = format!("src/inputs/{}.txt", day_padded);
|
let input_path = format!("src/inputs/{day_padded}.txt");
|
||||||
let example_path = format!("src/test_inputs/{}.txt", day_padded);
|
let example_path = format!("src/test_inputs/{day_padded}.txt");
|
||||||
let module_path = format!("src/bin/{}.rs", day_padded);
|
let module_path = format!("src/bin/{day_padded}.rs");
|
||||||
|
|
||||||
let mut file = match safe_create_file(&module_path) {
|
let mut file = match safe_create_file(&module_path) {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to create module file: {}", e);
|
eprintln!("Failed to create module file: {e}");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -71,7 +71,7 @@ fn main() {
|
||||||
println!("Created module file \"{}\"", &module_path);
|
println!("Created module file \"{}\"", &module_path);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to write module contents: {}", e);
|
eprintln!("Failed to write module contents: {e}");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ fn main() {
|
||||||
println!("Created empty input file \"{}\"", &input_path);
|
println!("Created empty input file \"{}\"", &input_path);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to create input file: {}", e);
|
eprintln!("Failed to create input file: {e}");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ fn main() {
|
||||||
println!("Created empty example file \"{}\"", &example_path);
|
println!("Created empty example file \"{}\"", &example_path);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to create example file: {}", e);
|
eprintln!("Failed to create example file: {e}");
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ macro_rules! solve {
|
||||||
pub fn read_file(folder: &str, day: u8) -> String {
|
pub fn read_file(folder: &str, day: u8) -> String {
|
||||||
let cwd = env::current_dir().unwrap();
|
let cwd = env::current_dir().unwrap();
|
||||||
|
|
||||||
let filepath = cwd.join("src").join(folder).join(format!("{:02}.txt", day));
|
let filepath = cwd.join("src").join(folder).join(format!("{day:02}.txt"));
|
||||||
|
|
||||||
let f = fs::read_to_string(filepath);
|
let f = fs::read_to_string(filepath);
|
||||||
f.expect("could not open input file")
|
f.expect("could not open input file")
|
||||||
|
@ -104,8 +104,7 @@ mod tests {
|
||||||
fn test_parse_exec_time() {
|
fn test_parse_exec_time() {
|
||||||
assert_approx_eq!(
|
assert_approx_eq!(
|
||||||
parse_exec_time(&format!(
|
parse_exec_time(&format!(
|
||||||
"🎄 Part 1 🎄\n0 (elapsed: 74.13ns){}\n🎄 Part 2 🎄\n0 (elapsed: 50.00ns){}",
|
"🎄 Part 1 🎄\n0 (elapsed: 74.13ns){ANSI_RESET}\n🎄 Part 2 🎄\n0 (elapsed: 50.00ns){ANSI_RESET}"
|
||||||
ANSI_RESET, ANSI_RESET
|
|
||||||
)),
|
)),
|
||||||
0_f64
|
0_f64
|
||||||
);
|
);
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::process::Command;
|
||||||
fn main() {
|
fn main() {
|
||||||
let total: f64 = (1..=25)
|
let total: f64 = (1..=25)
|
||||||
.map(|day| {
|
.map(|day| {
|
||||||
let day = format!("{:02}", day);
|
let day = format!("{day:02}");
|
||||||
|
|
||||||
let cmd = Command::new("cargo")
|
let cmd = Command::new("cargo")
|
||||||
.args(["run", "--release", "--bin", &day])
|
.args(["run", "--release", "--bin", &day])
|
||||||
|
@ -16,7 +16,7 @@ fn main() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("----------");
|
println!("----------");
|
||||||
println!("{}| Day {} |{}", ANSI_BOLD, day, ANSI_RESET);
|
println!("{ANSI_BOLD}| Day {day} |{ANSI_RESET}");
|
||||||
println!("----------");
|
println!("----------");
|
||||||
|
|
||||||
let output = String::from_utf8(cmd.stdout).unwrap();
|
let output = String::from_utf8(cmd.stdout).unwrap();
|
||||||
|
@ -40,7 +40,6 @@ fn main() {
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}Total:{} {}{:.2}ms{}",
|
"{ANSI_BOLD}Total:{ANSI_RESET} {ANSI_ITALIC}{total:.2}ms{ANSI_RESET}"
|
||||||
ANSI_BOLD, ANSI_RESET, ANSI_ITALIC, total, ANSI_RESET
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue