Day 1 Part 1 done, working on Part 2
This commit is contained in:
parent
4cbb61569d
commit
6ad1fa74d6
4 changed files with 84 additions and 5 deletions
|
|
@ -1,4 +1,32 @@
|
|||
|
||||
pub fn solve(input: &str) {
|
||||
|
||||
}
|
||||
let instructions = input
|
||||
.lines()
|
||||
.map(|str| {
|
||||
let distance = str.chars().next().map(|ch| &str[ch.len_utf8()..]).unwrap().parse::<i32>().unwrap();
|
||||
if str.starts_with('L') { -distance } else { distance }
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut counter = 0;
|
||||
let mut dial = 50;
|
||||
|
||||
for instruction in instructions {
|
||||
dial += instruction;
|
||||
|
||||
match dial {
|
||||
..=-1 => {
|
||||
dial += 100 * (dial / -100);
|
||||
}
|
||||
100.. => {
|
||||
dial %= 100;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if dial == 0 {
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
println!("part 1 counter: {}", counter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,44 @@
|
|||
|
||||
pub fn solve(input: &str) {
|
||||
|
||||
let instructions = input.lines().map(|str| {
|
||||
let distance = unsafe { str::from_utf8_unchecked( &str.bytes().collect::<Vec<_>>()[1..]).parse::<i32>().unwrap() };
|
||||
if str.bytes().next().unwrap() == b'L' {
|
||||
-distance
|
||||
} else {
|
||||
distance
|
||||
}
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
let mut counter = 0;
|
||||
let mut dial = 50;
|
||||
|
||||
println!("instr min: {}, max: {}", instructions.iter().min().unwrap(), instructions.iter().max().unwrap());
|
||||
|
||||
for instruction in instructions {
|
||||
// let old = dial;
|
||||
// let new = dial + instruction;
|
||||
|
||||
dial += instruction;
|
||||
|
||||
match dial {
|
||||
..=-1 => {
|
||||
counter += dial / -100;
|
||||
dial += 100 * (dial / -100); },
|
||||
100.. => {
|
||||
counter += dial / 100;
|
||||
dial %= 100;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// println!("{old} -> {new} = {dial}");
|
||||
|
||||
if dial == 0 {
|
||||
// println!("incremented!");
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
println!("counter: {}", counter);
|
||||
|
||||
}
|
||||
10
advent_of_code_2025/src/day1/test.txt
Normal file
10
advent_of_code_2025/src/day1/test.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
use paste::paste;
|
||||
mod utility;
|
||||
|
||||
solve_day!{1}
|
||||
// solve_day!{1}
|
||||
test_day!{1}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue