Compare commits
5 Commits
main
...
c40f1c822f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c40f1c822f | ||
|
|
c7ad6b02a8 | ||
|
|
4347fb2131 | ||
|
|
c7454a0202 | ||
|
|
44335ca03c |
81
2025/01.rs
Normal file
81
2025/01.rs
Normal 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
52
2025/02.rs
Normal 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
4604
2025/inputs/01_1.txt
Normal file
File diff suppressed because it is too large
Load Diff
10
2025/inputs/01_example.txt
Normal file
10
2025/inputs/01_example.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
1
2025/inputs/02_1.txt
Normal file
1
2025/inputs/02_1.txt
Normal 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
|
||||||
1
2025/inputs/02_example.txt
Normal file
1
2025/inputs/02_example.txt
Normal 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
|
||||||
Reference in New Issue
Block a user