clippies
This commit is contained in:
10
src/day2.rs
10
src/day2.rs
@@ -31,7 +31,7 @@ fn part1(input: &[RangeInclusive<u64>]) -> u64 {
|
||||
for r in input {
|
||||
for product in r.clone() {
|
||||
let prod_s = product.to_string();
|
||||
if prod_s.len() % 2 != 0 {
|
||||
if !prod_s.len().is_multiple_of(2) {
|
||||
continue;
|
||||
}
|
||||
let (left, right) = prod_s.split_at(prod_s.len() / 2);
|
||||
@@ -50,7 +50,7 @@ fn part2(input: &[RangeInclusive<u64>]) -> u64 {
|
||||
for product in r.clone() {
|
||||
let prod_s = product.to_string();
|
||||
for n in 1..=prod_s.len() / 2 {
|
||||
if prod_s.len() % n != 0 {
|
||||
if !prod_s.len().is_multiple_of(n) {
|
||||
continue;
|
||||
}
|
||||
if prod_s
|
||||
@@ -76,7 +76,7 @@ fn part1_arithmetic_brute(input: &[RangeInclusive<u64>]) -> u64 {
|
||||
// println!("Range: {:?}", r);
|
||||
for product in r.clone() {
|
||||
let n_digits = (product.ilog10() + 1) as usize;
|
||||
if n_digits % 2 != 0 {
|
||||
if !n_digits.is_multiple_of(2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ fn part2_arithmetic_brute(input: &[RangeInclusive<u64>]) -> u64 {
|
||||
|
||||
for n in 1..=n_digits / 2 {
|
||||
let repetitions = n_digits / n;
|
||||
if n_digits % n != 0 {
|
||||
if !n_digits.is_multiple_of(n) {
|
||||
continue;
|
||||
}
|
||||
let decade = POW10[n_digits - n];
|
||||
@@ -127,7 +127,7 @@ fn part1_clever(input: &[RangeInclusive<u64>]) -> u64 {
|
||||
for r in input {
|
||||
let n_digits = (r.start().ilog10() + 1) as usize;
|
||||
|
||||
let mut lhs = if n_digits % 2 != 0 {
|
||||
let mut lhs = if !n_digits.is_multiple_of(2) {
|
||||
// If the number of digits is odd, we start our guess at the first possibility in the next decade
|
||||
POW10[n_digits / 2]
|
||||
} else {
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
use lazy_static::lazy_static;
|
||||
use memoize::memoize;
|
||||
|
||||
type Bank = [u8];
|
||||
|
||||
#[aoc_generator(day3)]
|
||||
fn parse(input: &str) -> Vec<Vec<u8>> {
|
||||
input
|
||||
@@ -40,12 +35,12 @@ fn max_joltage(bank: Vec<u8>, n: usize) -> u64 {
|
||||
}
|
||||
|
||||
#[aoc(day3, part1)]
|
||||
fn part1(input: &Vec<Vec<u8>>) -> u64 {
|
||||
fn part1(input: &[Vec<u8>]) -> u64 {
|
||||
input.iter().map(|bank| max_joltage(bank.clone(), 2)).sum()
|
||||
}
|
||||
|
||||
#[aoc(day3, part2)]
|
||||
fn part2(input: &Vec<Vec<u8>>) -> u64 {
|
||||
fn part2(input: &[Vec<u8>]) -> u64 {
|
||||
input.iter().map(|bank| max_joltage(bank.clone(), 12)).sum()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
mod day3;
|
||||
mod day1;
|
||||
mod day2;
|
||||
mod day3;
|
||||
|
||||
use aoc_runner_derive::aoc_lib;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user