1
0
forked from danmax/aoc

Compare commits

..

6 Commits

6 changed files with 1177 additions and 0 deletions

8
.gitignore vendored Normal file
View File

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

1050
2025/1/deadvey/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
[package]
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

@@ -0,0 +1,59 @@
use std::fs;
use std::time::Instant;
// Right = up/increase
// Left = down/decrease
#[tokio::main]
async fn main()
{
let mut position: i32 = 50;
let mut total1: i32 = 0;
let mut total2: i32 = 0;
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 line in lines
{
let movement = line.chars().next().unwrap();
let mut number: i32 = line[1..line.len()].parse().unwrap();
if movement == 'L' {
number = -number
};
if number < 0 {
total2 += (100 - position - number) / 100 - (position == 0) as i32
}
else {
total2 += (number+position) / 100
};
position = (position + number).rem_euclid(100);
if position == 0 {
total1 += 1;
}
}
let end = start.elapsed();
println!("part1: {total1}");
println!("part2: {total2}");
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);
}

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