clippies
This commit is contained in:
BIN
.aoc_tiles/tiles/2025/03.png
Normal file
BIN
.aoc_tiles/tiles/2025/03.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.4 KiB |
@@ -1,6 +1,6 @@
|
|||||||
<!-- AOC TILES BEGIN -->
|
<!-- AOC TILES BEGIN -->
|
||||||
<h1 align="center">
|
<h1 align="center">
|
||||||
2025 - 4 ⭐ - Rust
|
2025 - 6 ⭐ - Rust
|
||||||
</h1>
|
</h1>
|
||||||
<a href="src/day1.rs">
|
<a href="src/day1.rs">
|
||||||
<img src=".aoc_tiles/tiles/2025/01.png" width="161px">
|
<img src=".aoc_tiles/tiles/2025/01.png" width="161px">
|
||||||
@@ -8,4 +8,7 @@
|
|||||||
<a href="src/day2.rs">
|
<a href="src/day2.rs">
|
||||||
<img src=".aoc_tiles/tiles/2025/02.png" width="161px">
|
<img src=".aoc_tiles/tiles/2025/02.png" width="161px">
|
||||||
</a>
|
</a>
|
||||||
|
<a href="src/day3.rs">
|
||||||
|
<img src=".aoc_tiles/tiles/2025/03.png" width="161px">
|
||||||
|
</a>
|
||||||
<!-- AOC TILES END -->
|
<!-- AOC TILES END -->
|
||||||
|
|||||||
10
src/day2.rs
10
src/day2.rs
@@ -31,7 +31,7 @@ fn part1(input: &[RangeInclusive<u64>]) -> u64 {
|
|||||||
for r in input {
|
for r in input {
|
||||||
for product in r.clone() {
|
for product in r.clone() {
|
||||||
let prod_s = product.to_string();
|
let prod_s = product.to_string();
|
||||||
if prod_s.len() % 2 != 0 {
|
if !prod_s.len().is_multiple_of(2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let (left, right) = prod_s.split_at(prod_s.len() / 2);
|
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() {
|
for product in r.clone() {
|
||||||
let prod_s = product.to_string();
|
let prod_s = product.to_string();
|
||||||
for n in 1..=prod_s.len() / 2 {
|
for n in 1..=prod_s.len() / 2 {
|
||||||
if prod_s.len() % n != 0 {
|
if !prod_s.len().is_multiple_of(n) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if prod_s
|
if prod_s
|
||||||
@@ -76,7 +76,7 @@ fn part1_arithmetic_brute(input: &[RangeInclusive<u64>]) -> u64 {
|
|||||||
// println!("Range: {:?}", r);
|
// println!("Range: {:?}", r);
|
||||||
for product in r.clone() {
|
for product in r.clone() {
|
||||||
let n_digits = (product.ilog10() + 1) as usize;
|
let n_digits = (product.ilog10() + 1) as usize;
|
||||||
if n_digits % 2 != 0 {
|
if !n_digits.is_multiple_of(2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ fn part2_arithmetic_brute(input: &[RangeInclusive<u64>]) -> u64 {
|
|||||||
|
|
||||||
for n in 1..=n_digits / 2 {
|
for n in 1..=n_digits / 2 {
|
||||||
let repetitions = n_digits / n;
|
let repetitions = n_digits / n;
|
||||||
if n_digits % n != 0 {
|
if !n_digits.is_multiple_of(n) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let decade = POW10[n_digits - n];
|
let decade = POW10[n_digits - n];
|
||||||
@@ -127,7 +127,7 @@ fn part1_clever(input: &[RangeInclusive<u64>]) -> u64 {
|
|||||||
for r in input {
|
for r in input {
|
||||||
let n_digits = (r.start().ilog10() + 1) as usize;
|
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
|
// If the number of digits is odd, we start our guess at the first possibility in the next decade
|
||||||
POW10[n_digits / 2]
|
POW10[n_digits / 2]
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use aoc_runner_derive::{aoc, aoc_generator};
|
use aoc_runner_derive::{aoc, aoc_generator};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use memoize::memoize;
|
use memoize::memoize;
|
||||||
|
|
||||||
type Bank = [u8];
|
|
||||||
|
|
||||||
#[aoc_generator(day3)]
|
#[aoc_generator(day3)]
|
||||||
fn parse(input: &str) -> Vec<Vec<u8>> {
|
fn parse(input: &str) -> Vec<Vec<u8>> {
|
||||||
input
|
input
|
||||||
@@ -40,12 +35,12 @@ fn max_joltage(bank: Vec<u8>, n: usize) -> u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[aoc(day3, part1)]
|
#[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()
|
input.iter().map(|bank| max_joltage(bank.clone(), 2)).sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[aoc(day3, part2)]
|
#[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()
|
input.iter().map(|bank| max_joltage(bank.clone(), 12)).sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
mod day3;
|
|
||||||
mod day1;
|
mod day1;
|
||||||
mod day2;
|
mod day2;
|
||||||
|
mod day3;
|
||||||
|
|
||||||
use aoc_runner_derive::aoc_lib;
|
use aoc_runner_derive::aoc_lib;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user