My submissions for Advent of Code 2025 adventofcode.com/2025
rust aoc
at main 24 lines 864 B view raw
1use std::fs::read_to_string; 2 3fn main() { 4 let invalid_sum: u64 = read_to_string("../input.txt") 5 .expect("failed to open input file") 6 .split(',') 7 .flat_map(|range| { 8 let (first_id, last_id) = range.split_once('-').expect("failed to parse range"); 9 let (first_id, last_id): (u64, u64) = ( 10 first_id.parse().expect("failed to parse first ID"), 11 last_id.trim_end().parse().expect("failed to parse last ID"), 12 ); 13 14 first_id..=last_id 15 }) 16 .filter(|id| { 17 let id = id.to_string(); 18 let digit_count = id.len(); 19 (1..=(digit_count / 2)) 20 .any(|pattern_len| id[0..pattern_len].repeat(digit_count / pattern_len) == id) 21 }) 22 .sum(); 23 println!("The sum of all invalid IDs is {invalid_sum}!") 24}