Compare commits

...

5 Commits

Author SHA1 Message Date
Lol3rrr
c40f1c822f Implement 2025 - Day 2 - Part 2 2026-01-08 20:54:19 +01:00
Lol3rrr
c7ad6b02a8 Implement 2025 - Day 2 - Part 1 2026-01-08 20:24:22 +01:00
Lol3rrr
4347fb2131 Implement 2025 - Day 1 - Part 2 2026-01-08 19:42:42 +01:00
Lol3rrr
c7454a0202 Implement 2025 - Day 1 - Part 1 2026-01-08 19:21:43 +01:00
Lol3rrr
44335ca03c Basic README input 2026-01-08 19:20:56 +01:00
7 changed files with 4750 additions and 0 deletions

81
2025/01.rs Normal file
View File

@@ -0,0 +1,81 @@
---cargo
---
static CONTENT: &'static str = include_str!("./inputs/01_1.txt");
#[derive(Debug)]
enum Direction {
Left,
Right,
}
#[derive(Debug)]
struct Rotation {
direction: Direction,
amount: usize,
}
fn main() {
let rotations: Vec<Rotation> = CONTENT.lines().map(|l| l.trim()).filter(|l| !l.is_empty()).map(|l| {
let (direction, raw_amount) = l.split_at(1);
let direction = match direction {
"L" => Direction::Left,
"R" => Direction::Right,
other => unreachable!("Unknown Direction: {:?}", other),
};
let amount = match raw_amount.parse::<usize>() {
Ok(a) => a,
Err(e) => unreachable!("Invalid Amount ({:?}): {:?}", raw_amount, e),
};
Rotation {
direction,
amount,
}
}).collect();
println!("Rotations: {:#?}", rotations);
let mut count: usize = 0;
let mut state: isize = 50;
for rot in rotations.iter() {
if rot.amount >= 100 {
count += rot.amount / 100;
}
let amount = rot.amount % 100;
if amount == 0 {
continue;
}
match rot.direction {
Direction::Left => {
if state != 0 && amount > state as usize {
count += 1;
}
state = state.strict_sub_unsigned(amount);
state = state.strict_rem_euclid(100);
if state == 0 {
count += 1;
}
}
Direction::Right => {
state = state.strict_add_unsigned(amount);
if state >= 100 {
count += 1;
}
state = state.strict_rem_euclid(100);
}
};
println!("Applying {:?} => {} ({})", rot, state, count);
}
println!("Result: {}", count);
}

52
2025/02.rs Normal file
View File

@@ -0,0 +1,52 @@
---cargo
---
static CONTENT: &'static str = include_str!("./inputs/02_1.txt");
fn main() {
let ranges: Vec<_> = CONTENT.split(',').map(|l| l.trim()).filter(|l| !l.is_empty()).map(|l| {
let (raw_start, raw_end) = l.split_once('-').unwrap();
let start: usize = raw_start.parse().unwrap();
let end: usize = raw_end.parse().unwrap();
start..=end
}).collect();
println!("Ranges: {:?}", ranges);
let mut result = 0;
for r in ranges.iter() {
for v in r.clone() {
let v_len = v.ilog10() + 1;
let mut iter = (1..=v_len/2).filter_map(|len| {
if v_len % len != 0 {
return None;
}
let mut seqs = (0..v_len/len).map(|i| {
let offset = 10_usize.pow(i*len);
let mask = 10_usize.pow(len);
(v/offset) % mask
});
let first = match seqs.next() {
Some(f) => f,
None => return None,
};
let invalid = seqs.all(|s| s == first);
invalid.then_some((first, len, v_len/len))
});
let first = iter.next();
if first.is_some() {
println!("{} - {:?}", v, first);
result += v;
}
}
}
println!("Result: {}", result);
}

4604
2025/inputs/01_1.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82

1
2025/inputs/02_1.txt Normal file
View File

@@ -0,0 +1 @@
17330-35281,9967849351-9967954114,880610-895941,942-1466,117855-209809,9427633930-9427769294,1-14,311209-533855,53851-100089,104-215,33317911-33385573,42384572-42481566,43-81,87864705-87898981,258952-303177,451399530-451565394,6464564339-6464748782,1493-2439,9941196-10054232,2994-8275,6275169-6423883,20-41,384-896,2525238272-2525279908,8884-16221,968909030-969019005,686256-831649,942986-986697,1437387916-1437426347,8897636-9031809,16048379-16225280

View File

@@ -0,0 +1 @@
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124

View File

@@ -0,0 +1 @@
# Advent of Code