Compare commits

6 Commits
main ... main

Author SHA1 Message Date
522b0d364f DeaDvey day 4 2025-12-04 14:16:41 +00:00
fbc32d12de DeaDvey d3 optimisations & danmax 2025-12-03 20:40:47 +00:00
bad7dafe2b Merge branch 'main' of ssh://git.javalsai.tuxcord.net:1022/deadvey/aoc 2025-12-03 10:53:15 +00:00
3e214636ca Day 3 2025-12-03 10:52:12 +00:00
51926a19bf merge upstream 2025-12-02 08:31:25 +01:00
ba2391bd8e Day 2 deadvey's solution 2025-12-02 07:30:57 +00:00
8 changed files with 333 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,73 @@
use std::fs;
use std::time::Instant;
fn algorithm(vector: &Vec<Vec<&str>>) -> (u64, u64) {
let mut total1: u64 = 0;
let mut total2: u64 = 0;
for pair in vector
{
let num_1: u64 = pair[0].parse().unwrap();
let num_2: u64 = pair[1].parse().unwrap();
for num in num_1..=num_2 { // Loop over each number in the range
let num_string = num.to_string();
let num_length = num_string.len();
for chunk_width in (1..=(num_length/2)).rev() {
if num_length % chunk_width == 0 {
let chunks = num_length / chunk_width;
let mut same: bool = true;
let mut previous = &num_string[0..chunk_width];
for i in 0..chunks {
let current = &num_string[i*chunk_width..i*chunk_width+chunk_width];
if current != previous {
same = false;
break;
}
previous = current;
}
if same {
total2 += num;
if chunks == 2 {
total1 += num;
}
break;
}
}
}
}
}
(total1, total2)
}
// you can find the invalid IDs by looking for any ID which is made only of some sequence of digits repeated twice.
// So, 55 (5 twice), 6464 (64 twice), and 123123 (123 twice) would all be invalid IDs.
fn main() {
let start = Instant::now();
let mut file_contents: String = fs::read_to_string("../large.txt").unwrap();
file_contents.pop();// Remove \n
// Split it up
let pairs: Vec<Vec<&str>> = file_contents
.split(",")
.collect::<Vec<&str>>()
.iter()
.map(|s| s.split('-').collect())
.collect();
let file_read = start.elapsed();
let (total1, total2) = algorithm(&pairs);
// There's a lot of converting between int and string
let end = start.elapsed();
println!("part1: {total1}");
println!("part2: {total2}");
println!("Times:
File read: {:.2?}
Loop: {:.2?}
Avg time per pair: {:.2?}
Total: {:.4?}
",
file_read,
end-file_read,
(end-file_read)/(100).try_into().unwrap(),
end);
}

6
2025/3/danmax/Cargo.toml Normal file
View File

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

18
2025/3/danmax/src/main.rs Normal file
View File

@@ -0,0 +1,18 @@
fn main() {
let raw = std::fs::read_to_string("../large.txt").unwrap();
let start = std::time::Instant::now();
let mut banks = raw.split('\n').collect::<Vec<&str>>();
banks.pop();
let mut sol = 0;
for bank in banks {
let batteries = bank.chars().map(|x| (x as u8) - 48).collect::<Vec<u8>>();
let mut combos = vec![];
for i in 0..batteries.len() - 1 {
let num = (batteries[i] * 10) + batteries[(i + 1)..batteries.len()].iter().max().unwrap();
combos.push(num);
}
sol += *combos.iter().max().unwrap() as u64;
}
let end = start.elapsed();
dbg!(sol, end);
}

View File

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

View File

@@ -0,0 +1,94 @@
use std::fs;
use std::time::Instant;
use std::ptr;
fn algorithm(banks: &Vec<&str>) -> (u64, u64)
{
let bank_length = banks[0].len();
let mut total1: u64 = 0;
let mut total2: u64 = 0;
for bank in banks {
let mut prev_index = 0;
let mut joltages: [u64; 12] = [0; 12];
let mut highest: u64 = 0;
let mut overall_index = 0;
// part 2
for i in 0..=11 {
for joltage in bank[prev_index..(bank_length-(11-i))].bytes() {
overall_index += 1;
if joltage as u64 > highest {
prev_index = overall_index;
unsafe {ptr::write(&mut highest as *mut u64, joltage as u64);}
if joltage == 57 { break; }
}
}
overall_index = prev_index;
joltages[i] = highest ^ 48;
highest = 0;
}
total2 += joltages[0] * 10_u64.pow(11)
+ joltages[1] * 10_u64.pow(10)
+ joltages[2] * 10_u64.pow(9)
+ joltages[3] * 10_u64.pow(8)
+ joltages[4] * 10_u64.pow(7)
+ joltages[5] * 10_u64.pow(6)
+ joltages[6] * 10_u64.pow(5)
+ joltages[7] * 10_u64.pow(4)
+ joltages[8] * 10_u64.pow(3)
+ joltages[9] * 10_u64.pow(2)
+ joltages[10] * 10_u64
+ joltages[11];
// part 1
prev_index = 0;
for i in 0..=10 {
if joltages[i] > highest.into() {
unsafe {ptr::write(&mut highest as *mut u64, joltages[i] as u64);}
prev_index = i+1;
if joltages[i] == 9 { break; }
}
}
total1 += highest * 10;
highest = 0;
for i in prev_index..=11 {
if joltages[i] > highest.into() {
unsafe {
ptr::write(&mut highest as *mut u64, joltages[i] as u64);}
if joltages[i] == 9 { break; }
}
}
total1 += highest;
}
(total1, total2)
}
// 987654321111111 = 1 bank
// 811111111111119
// 234234234234278
// 818181911112111
fn main() {
let file_contents: String = fs::read_to_string("../large.txt").unwrap();
let start = Instant::now();
let mut banks: Vec<&str> = file_contents
.split('\n')
.collect::<Vec<&str>>();
banks.pop();
let preamble = start.elapsed();
let (total1, total2) = algorithm(&banks);
let end = start.elapsed();
println!("part1: {total1}");
println!("part2: {total2}");
println!("Times:
Preamble: {:.2?}
Loop: {:.2?}
Avg time per bank: {:.2?}
Total: {:.4?}
",
preamble,
end-preamble,
(end-preamble)/(10000).try_into().unwrap(),
end);
}

View File

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

124
2025/4/deadvey/src/main.rs Normal file
View File

@@ -0,0 +1,124 @@
use std::fs;
use std::time::Instant;
fn remove_dem(rows: &mut Vec<Vec<char>>, i: usize, j: usize) {
rows[i][j] = 'x';
}
fn algorithm(rows: &mut Vec<Vec<char>>) -> (u64, u64) {
let mut total1: u64 = 0;
let mut total2: u64 = 0;
let grid_width: usize = rows[0].len().try_into().unwrap();
let grid_height: usize = rows.len().try_into().unwrap();
let directions = vec![(-1,0),(1,0),(0,-1),(0,1),(-1,-1),(-1,1),(1,-1),(1,1)];
let mut removed: bool = true;
let mut count: u8 = 66;
// First loop
for i in 0usize..(grid_height) {
for j in 0usize..(grid_width) {
if rows[i][j] == '@' { // @
let mut surrounded_by = 0;
for (dr, dc) in &directions {
let new_row = i as isize + dr;
let new_column = j as isize + dc;
if new_row >= grid_height as isize {
continue
}
if new_row < 0 {
continue
}
if new_column >= grid_width as isize {
continue
}
if new_column < 0 {
continue
}
if rows[new_row as usize][new_column as usize] == '@'
|| rows[new_row as usize][new_column as usize] == 'A'
{
surrounded_by += 1;
}
if surrounded_by >= 4 {
break
}
}
if surrounded_by < 4 {
rows[i][j] = 'A';
total2 += 1;
total1 += 1;
removed = true;
}
}
}
}
// All other loops
while removed {
removed = false;
for i in 0usize..(grid_height) {
for j in 0usize..(grid_width) {
if rows[i][j] == '@' { // @
let mut surrounded_by = 0;
for (dr, dc) in &directions {
let new_row = i as isize + dr;
let new_column = j as isize + dc;
if new_row >= grid_height as isize {
continue
}
if new_row < 0 {
continue
}
if new_column >= grid_width as isize {
continue
}
if new_column < 0 {
continue
}
if rows[new_row as usize][new_column as usize] == '@'
{
surrounded_by += 1;
}
else if rows[new_row as usize][new_column as usize] == count as char
{
surrounded_by += 1;
}
if surrounded_by >= 4 { break }
}
if surrounded_by < 4 {
rows[i][j] = count as char;
total2 += 1;
removed = true;
}
}
}
}
count += 1;
}
(total1, total2)
}
fn main() {
let file_contents: String = fs::read_to_string("../large.txt").unwrap();
let start = Instant::now();
let mut grid: Vec<Vec<char>> = file_contents
.lines()
.map(|line| line.chars().collect())
.collect();
let preamble = start.elapsed();
let (total1, total2) = algorithm(&mut grid);
let end = start.elapsed();
println!("part1: {total1}");
println!("part2: {total2}");
println!("Times:
Preamble: {:.2?}
Loop: {:.2?}
Avg time per bank: {:.2?}
Total: {:.4?}
",
preamble,
end-preamble,
(end-preamble)/(grid.len()).try_into().unwrap(),
end);
}