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

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"
version = "0.1.0"
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::io;
use std::time::Instant;
// Right = up/increase
// 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 total1: 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 mut number: i32 = lines[index][1..lines[index].len()].parse().unwrap();
let movement = line.chars().next().unwrap();
let mut number: i32 = line[1..line.len()].parse().unwrap();
if movement == "L" {
if movement == 'L' {
number = -number
};
if number < 0 {
@@ -41,8 +43,17 @@ fn main() -> io::Result<()>
let end = start.elapsed();
println!("part1: {total1}");
println!("part2: {total2}");
println!("Took: {:.2?}",end);
Ok(())
println!("Times:
File read: {:.2?}
Preamble: {:.2?}
Loop: {:.2?}
Average Loop: {:.2?}
Total: {:.2?}
",
file_read,
preamble,
end-preamble,
(end-preamble)/(100000).try_into().unwrap(),
end);
}