add until day05-1

This commit is contained in:
timeshifter
2026-06-05 22:12:35 +02:00
parent 89c728010c
commit c7a5adc00a
26 changed files with 2326 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
use std::collections::HashSet;
#[cfg(debug_assertions)]
const FILENAME: &str = "example.txt";
#[cfg(not(debug_assertions))]
const FILENAME: &str = "input.txt";
fn main() {
let data = std::fs::read_to_string(FILENAME).unwrap();
part_1(&data);
part_2(&data);
}
fn part_2(data: &str) {
let mut hs = HashSet::new();
let mut xs: isize = 0;
let mut ys: isize = 0;
let mut xr: isize = 0;
let mut yr: isize = 0;
hs.insert((xs, ys));
for (idx, c) in data.trim().chars().enumerate() {
let x;
let y;
if idx % 2 == 0 {
x = &mut xs;
y = &mut ys;
} else {
x = &mut xr;
y = &mut yr;
}
match c {
'^' => *y += 1,
'>' => *x += 1,
'<' => *x -= 1,
'v' => *y -= 1,
_ => unreachable!(),
};
hs.insert((*x, *y));
}
println!("{}", hs.len());
}
fn part_1(data: &str) {
let mut hs = HashSet::new();
let mut x: isize = 0;
let mut y: isize = 0;
hs.insert((x, y));
for c in data.trim().chars() {
match c {
'^' => y += 1,
'>' => x += 1,
'<' => x -= 1,
'v' => y -= 1,
_ => unreachable!(),
};
hs.insert((x, y));
}
println!("{}", hs.len());
}