Compare commits

..

No commits in common. "49650c8a28bf90eb0503d78eb70d220ef2704c6a" and "39c5eb1897d145acf7780692006b8183020a2545" have entirely different histories.

3 changed files with 1 additions and 104 deletions

View File

@ -1,6 +1,6 @@
pub mod d1;
pub mod d2;
pub mod d3;
// pub mod d3;
// pub mod d4;
// pub mod d5;
// pub mod d6;

View File

@ -1,102 +0,0 @@
#![allow(unused_imports)]
use crate::prelude::*;
pub type I = &'static str;
pub type O = u64;
fn _silver (data: I) -> O {
let mut sum = 0;
let mut data = data;
while let Some(f) = data.find("mul(") {
data = &data[f..];
let start = 4;
let Some(fin) = data.find(')') else { break };
let inside = &data[start..fin];
if let Some((left, right)) = inside.split_once(',') {
if let Ok(left) = left.parse::<u64>() && let Ok(right) = right.parse::<u64>() {
sum += left * right;
} else {
data = &data[start..];
continue;
}
} else {
data = &data[start..];
continue;
}
data = &data[fin+1..];
}
sum
}
fn _gold (data: I) -> O {
let mut sum = 0;
let mut enabled = true;
let mut data = data;
loop {
let mul = data.find("mul(").unwrap_or(usize::MAX);
let _do = data.find("do()").unwrap_or(usize::MAX);
let dont = data.find("don't()").unwrap_or(usize::MAX);
if [mul, _do, dont].iter().all(|&e| e == usize::MAX) {
break;
}
let next = mul.min(_do).min(dont);
if next == mul {
data = &data[next..];
let start = 4;
let Some(fin) = data.find(')') else { break };
let inside = &data[start..fin];
if let Some((left, right)) = inside.split_once(',') {
if let Ok(left) = left.parse::<u64>() && let Ok(right) = right.parse::<u64>() {
if enabled {
sum += left * right;
}
} else {
data = &data[start..];
continue;
}
} else {
data = &data[start..];
continue;
}
data = &data[fin+1..];
} else if next == _do {
enabled = true;
data = &data[next+4..];
} else if next == dont {
enabled = false;
data = &data[next+7..];
}
}
sum
}
#[cfg(test)]
mod test {
use super::*;
fn read () -> &'static str {
inc!(3)
}
#[test]
fn silver () {
let data = read();
let ans = _silver(data);
assert_eq!(ans, 181345830)
}
#[test]
fn gold () {
let data = read();
let ans = _gold(data);
assert_eq!(ans, 98729041)
}
}

View File

@ -3,7 +3,6 @@
#![feature(decl_macro)]
#![feature(iter_array_chunks)]
#![feature(binary_heap_into_iter_sorted)]
#![feature(type_alias_impl_trait)]
pub mod days;
pub mod utils;