add initial data

This commit is contained in:
timeshifter committed 2026-09-04 16:08:03 +02:00
commit c4e841b4bc
43 files changed
+5284

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aoc01"
version = "0.1.0"
+8
View File
@@ -0,0 +1,8 @@
[package]
name = "aoc01"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+2000
View File
File diff suppressed because it is too large. Load diff
+10
View File
@@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263
+43
View File
@@ -0,0 +1,43 @@
use std::fs;
fn main() {
let data = read_data("data.txt");
let increase_count = process(&data);
println!("Increasing values: {}", increase_count);
let increase_count = process_windowed(&data);
println!("Increasing values windowed: {}", increase_count);
}
fn read_data(filename: &str) -> String {
fs::read_to_string(filename).expect("Could not read file")
}
fn process(data: &str) -> i32 {
let mut last_value = i32::MAX;
let mut increase_count = 0;
for line in data.lines() {
let value = line.parse::<i32>().unwrap();
if value > last_value {
increase_count += 1
}
last_value = value;
}
increase_count
}
fn process_windowed(data: &str) -> i32 {
let mut last_value = i32::MAX;
let mut increase_count = 0;
for i in 0..1998 {
let mut value = 0;
for j in 0..3 {
value += data.lines().nth(i + j).unwrap().parse::<i32>().unwrap();
}
if value > last_value {
increase_count += 1
}
last_value = value;
}
increase_count
}