امن برياني
94 subscribers
372 photos
56 videos
12 files
110 links
What I cannot create, I do not understand.
I share what I make here, alongside some silly memes and other stuff
Download Telegram
AoC 2025 Day 2
fn is_repeated_twice(id: u128) -> bool {
let id_string = id.to_string();
let id_len = id_string.len();
// if each half of the id-string are equal then the ID is repeated
let (ids1, ids2) = id_string.split_at((id_len) / 2);
ids1 == ids2
}
fn is_repeated(id: u128) -> bool {
let id_string = id.to_string();
let id_len = id_string.len();

// try all possible pattern lengths
for block_len in 1..=(id_len / 2) {
// if the block-len is not
// divisible by id-len then
// it's not a repeated id
if id_len % block_len != 0 {
continue;
}
// the first block is what we will compare the other blocks to
let first_block = &id_string[..block_len];
let mut ok = true;
for i in (block_len..id_len).step_by(block_len) {
// if any block does not equal the first one then this is not
// a repeating pattern
if &id_string[i..i + block_len] != first_block {
ok = false;
break;
}
}
if ok {
return true;
}
}
false
}
fn main() {
let ranges = include_str!("./input2.txt").trim().split(",").map(|range| {
let (first, second) = range.split_once("-").unwrap();
let first = first.parse::<u128>().unwrap();
let second = second.parse::<u128>().unwrap();
first..=second
});
let p1: u128 = ranges
.clone()
.map(|x| x.filter(|&n| is_repeated_twice(n)).sum::<u128>())
.sum();
let p2: u128 = ranges
.map(|x| x.filter(|&n| is_repeated(n)).sum::<u128>())
.sum();
println!("solution: {p1}");
println!("solution: {p2}");
}

https://adventofcode.com/2025/day/2
happy new year everyone
❤4
الالمانيين ياخي
💋1
Forwarded from Btetah for "سچ" (btetah)
عاش هاي الصحفية طشرت معلوماتنا
شكد حلو من ينشرون رقمك واسمك وانت لابيها ولا عليها
🤣4
❤1💋1
❤3❤‍🔥1💋1
امن برياني
Photo
انشلع كلبنا يلا اشتعل الفحم (محد قبل يستعمل نفط)
💋1
🤔1💋1
امن برياني
Photo
راح نطلع من الجامعة تالي الليل
💋1
تم التعليقات
💋1