1
0
forked from danmax/aoc

Added mememan's code and updated mine a bit

This commit is contained in:
2025-12-01 20:40:16 +00:00
parent 36a19996da
commit f1260bd73d
6 changed files with 1135 additions and 17 deletions

8
.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
large.txt
medium.txt
small.txt
target
debug
*.swp
Cargo.lock

1043
2025/1/deadvey/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,3 +2,7 @@
name = "deadvey" name = "deadvey"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies]
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }
trash_parallelism = "0.1.102"

View File

@@ -1,29 +1,31 @@
use std::fs; use std::fs;
use std::io;
use std::time::Instant; use std::time::Instant;
// Right = up/increase // Right = up/increase
// Left = down/decrease // Left = down/decrease
fn main() -> io::Result<()> #[tokio::main]
async fn main()
{ {
let start = Instant::now();
let file_contents: String = fs::read_to_string("large.txt")?;
let lines: Vec<&str> = file_contents
.split("\n")
.collect();
let mut position: i32 = 50; let mut position: i32 = 50;
let mut total1: i32 = 0; let mut total1: i32 = 0;
let mut total2: i32 = 0; let mut total2: i32 = 0;
println!("The dial starts by pointing at {position}"); let start = Instant::now();
let file_contents: String = fs::read_to_string("../large.txt").unwrap();
//let file_contents = read_file_to_string_async("large.txt").await.unwrap();
let file_read = start.elapsed();
let mut lines: Vec<&str> = file_contents
.split("\n")
.collect();
lines.pop();
let preamble = start.elapsed();
for index in 0..&lines.len()-1 for line in lines
{ {
let movement = &lines[index][0..1]; let movement = line.chars().next().unwrap();
let mut number: i32 = lines[index][1..lines[index].len()].parse().unwrap(); let mut number: i32 = line[1..line.len()].parse().unwrap();
if movement == "L" { if movement == 'L' {
number = -number number = -number
}; };
if number < 0 { if number < 0 {
@@ -41,8 +43,17 @@ fn main() -> io::Result<()>
let end = start.elapsed(); let end = start.elapsed();
println!("part1: {total1}"); println!("part1: {total1}");
println!("part2: {total2}"); println!("part2: {total2}");
println!("Took: {:.2?}",end); println!("Times:
File read: {:.2?}
Preamble: {:.2?}
Ok(()) Loop: {:.2?}
Average Loop: {:.2?}
Total: {:.2?}
",
file_read,
preamble,
end-preamble,
(end-preamble)/(100000).try_into().unwrap(),
end);
} }

View File

@@ -0,0 +1,6 @@
[package]
name = "mememan"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@@ -0,0 +1,46 @@
use std::fs;
fn main() {
let start = std::time::Instant::now();
let raw = fs::read_to_string("../large.txt").unwrap();
let mut formatted: Vec<&str> = raw.split("\n").collect();
formatted.pop();
let mut point: i32 = 50;
let mut password_one = 0;
let mut password_two = 0;
for rot in formatted {
let mut chars = rot.chars();
let dir = chars.next().unwrap();
let dist = chars.as_str().parse::<i32>().unwrap();
if dir == 'L' {
if point - dist < 1 {
password_two += ((point - dist).abs() as f32 / 100.0).ceil() as i32;
point = (point - dist).rem_euclid(100);
if point == 0 {
password_one +=1;
}
// dbg!(point, ((point - dist).abs() as f32 / 100.0).ceil());
continue;
}
point = (point - dist).rem_euclid(100);
} else {
if point + dist > 99 {
password_two += ((point + dist) as f32 / 100.0).floor() as i32;
point = (point + dist).rem_euclid(100);
if point == 0 {
password_one += 1;
}
// dbg!(point, ((point + dist) as f32 / 100.0).floor());
continue;
}
point = (point + dist).rem_euclid(100);
}
if point == 0 {
password_one += 1;
password_two += 1;
}
// dbg!(point);
}
dbg!(password_one, password_two, std::time::Instant::now() - start);
}