This commit is contained in:
2025-12-02 21:35:09 -08:00
parent 47f7068705
commit f89bbf2bff
5 changed files with 12 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@@ -1,6 +1,6 @@
<!-- AOC TILES BEGIN -->
<h1 align="center">
2025 - 4 ⭐ - Rust
2025 - 6 ⭐ - Rust
</h1>
<a href="src/day1.rs">
<img src=".aoc_tiles/tiles/2025/01.png" width="161px">
@@ -8,4 +8,7 @@
<a href="src/day2.rs">
<img src=".aoc_tiles/tiles/2025/02.png" width="161px">
</a>
<a href="src/day3.rs">
<img src=".aoc_tiles/tiles/2025/03.png" width="161px">
</a>
<!-- AOC TILES END -->

View File

@@ -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 {

View File

@@ -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()
}

View File

@@ -1,6 +1,6 @@
mod day3;
mod day1;
mod day2;
mod day3;
use aoc_runner_derive::aoc_lib;