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
+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;
}
}
}