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
+1
View File
@@ -0,0 +1 @@
**/target
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "day01"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "day01"
version = "0.1.0"
edition = "2024"
[dependencies]
+1
View File
@@ -0,0 +1 @@
()())
+1
View File
File diff suppressed because one or more lines are too long
+32
View File
@@ -0,0 +1,32 @@
#[cfg(debug_assertions)]
const FILENAME: &str = "example.txt";
#[cfg(not(debug_assertions))]
const FILENAME: &str = "input.txt";
fn main() {
let data = std::io::read_to_string(std::fs::File::open(FILENAME).unwrap()).unwrap();
let s = data.trim();
part_1(s);
part_2(s);
}
fn part_1(data: &str) {
let result: i64 = data.chars().map(|c| if c == '(' { 1 } else { -1 }).sum();
println!("{result}");
}
fn part_2(data: &str) {
let mut current_floor: i64 = 0;
for (i, c) in data.chars().enumerate() {
if c == '(' {
current_floor += 1;
} else {
current_floor -= 1;
}
if current_floor == -1 {
println!("{}", i + 1);
break;
}
}
}
+25
View File
@@ -0,0 +1,25 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "day02"
version = "0.1.0"
dependencies = [
"itertools",
]
[[package]]
name = "either"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e"
[[package]]
name = "itertools"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
dependencies = [
"either",
]
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "day02"
version = "0.1.0"
edition = "2024"
[dependencies]
itertools = "0.14.0"
+2
View File
@@ -0,0 +1,2 @@
2x3x4
1x1x10
+1000
View File
File diff suppressed because it is too large Load Diff
+46
View File
@@ -0,0 +1,46 @@
use itertools::Itertools;
#[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 sum = 0;
for line in data.lines() {
let edges: Vec<_> = line
.split('x')
.map(|x| x.parse::<usize>().unwrap())
.collect();
let perimeter = edges.iter().sorted().take(2).sum::<usize>() * 2;
let volume = edges.iter().product::<usize>();
sum += perimeter + volume;
}
println!("{sum}");
}
fn part_1(data: &str) {
let mut sum = 0;
for line in data.lines() {
let sides: Vec<_> = line
.split('x')
.map(|x| x.parse::<usize>().unwrap())
.combinations(2)
.map(|x| x[0] * x[1])
.collect();
let smallest = sides.iter().min().copied().unwrap();
sum += sides.into_iter().sum::<usize>() * 2 + smallest;
}
println!("{sum}");
}
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "day03"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "day03"
version = "0.1.0"
edition = "2024"
[dependencies]
+1
View File
@@ -0,0 +1 @@
^v^v^v^v^v
+1
View File
File diff suppressed because one or more lines are too long
+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());
}
+16
View File
@@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "day04"
version = "0.1.0"
dependencies = [
"md5",
]
[[package]]
name = "md5"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae960838283323069879657ca3de837e9f7bbb4c7bf6ea7f1b290d5e9476d2e0"
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "day04"
version = "0.1.0"
edition = "2024"
[dependencies]
md5 = "0.8.0"
+1
View File
@@ -0,0 +1 @@
abcdef
+1
View File
@@ -0,0 +1 @@
yzbqklnj
+27
View File
@@ -0,0 +1,27 @@
#[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_and_2(data.trim(), 5);
part_1_and_2(data.trim(), 6);
}
fn part_1_and_2(key: &str, length: usize) {
for i in 1.. {
let mut input = String::from(key);
input.push_str(&i.to_string());
let hash = md5::compute(input);
let hash_str = format!("{:x?}", hash);
if hash_str.chars().take(length).all(|c| c == '0') {
println!("{i}");
break;
}
}
}
+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "day05"
version = "0.1.0"
+6
View File
@@ -0,0 +1,6 @@
[package]
name = "day05"
version = "0.1.0"
edition = "2024"
[dependencies]
+9
View File
@@ -0,0 +1,9 @@
ugknbfddgicrmopn
aaa
jchzalrnumimnmhp
haegwjzuvuyypxyu
dvszwmarrgswjxmb
qjhvhtzxzqqjkmpb
xxyxx
uurcxstgmygtbstg
ieodomkazucvgmuy
+1000
View File
File diff suppressed because it is too large Load Diff
+40
View File
@@ -0,0 +1,40 @@
#[cfg(debug_assertions)]
const FILENAME: &str = "example.txt";
#[cfg(not(debug_assertions))]
const FILENAME: &str = "input.txt";
const VOWELS: &str = "aeiou";
const FORBIDDEN: [&str; 4] = ["ab", "cd", "pq", "xy"];
fn main() {
let data = std::fs::read_to_string(FILENAME).unwrap();
part_1_and_2(&data, is_nice_1);
part_1_and_2(&data, is_nice_2);
}
fn part_1_and_2<T: Fn(&&str) -> bool>(data: &str, f: T) {
let sum = data.lines().filter(f).count();
println!("{sum}");
}
fn is_nice_1(s: &&str) -> bool {
let vowel_count = s.chars().filter(|c| VOWELS.contains(*c)).count();
let double_letter = s.chars().zip(s.chars().skip(1)).any(|(a, b)| a == b);
let has_forbidden_tuple = s
.chars()
.zip(s.chars().skip(1))
.map(|(a, b)| format!("{a}{b}"))
.any(|tuple| FORBIDDEN.contains(&tuple.as_str()));
vowel_count >= 3 && double_letter && !has_forbidden_tuple
}
fn is_nice_2(s: &&str) -> bool {
let mut subrule_1 = false;
let mut subrule_2 = false;
subrule_1 && subrule_2
}