Skip to content

Commit

Permalink
Add day9 part1
Browse files Browse the repository at this point in the history
  • Loading branch information
qselle committed Dec 15, 2024
1 parent 97624de commit 5d31475
Showing 1 changed file with 64 additions and 11 deletions.
75 changes: 64 additions & 11 deletions src/day9.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aoc_runner_derive::{aoc, aoc_generator};

#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub enum Disk {
File { id: usize, blocks: usize },
Free { blocks: usize },
Expand Down Expand Up @@ -28,16 +28,69 @@ pub fn input_generator(input: &str) -> Vec<Disk> {

#[aoc(day9, part1)]
pub fn part1(input: &[Disk]) -> usize {
dbg!(input);
0
}
for i in input {
match i {
Disk::File { id, blocks } => {
print!("{}", id.to_string().repeat(*blocks));
}
Disk::Free { blocks } => {
print!("{}", ".".repeat(*blocks));
}
}
}
println!();

let mut i = 0;
let mut input = input.to_vec();
let mut results: Vec<usize> = Vec::new();

loop {
if i > input.len() {
break;
}

match input[i] {
Disk::File { id, blocks } => results.extend(std::iter::repeat(id).take(blocks)),
Disk::Free {
blocks: free_blocks,
} => loop {
if let Some(last) = input.pop() {
match last {
Disk::Free { blocks } => continue,
Disk::File { id: _, blocks } => {
if blocks == *free_blocks {

Check failure on line 61 in src/day9.rs

View workflow job for this annotation

GitHub Actions / Check

type `usize` cannot be dereferenced

Check failure on line 61 in src/day9.rs

View workflow job for this annotation

GitHub Actions / Lints

type `usize` cannot be dereferenced
results.push(last);

Check failure on line 62 in src/day9.rs

View workflow job for this annotation

GitHub Actions / Check

mismatched types

Check failure on line 62 in src/day9.rs

View workflow job for this annotation

GitHub Actions / Lints

mismatched types
}
}
}
} else {
break;
}
},
}
}

for i in results {
match i {
Disk::File { id, blocks } => {

Check failure on line 75 in src/day9.rs

View workflow job for this annotation

GitHub Actions / Check

mismatched types

Check failure on line 75 in src/day9.rs

View workflow job for this annotation

GitHub Actions / Lints

mismatched types
print!("{}", id.to_string().repeat(blocks));
}
Disk::Free { blocks } => {

Check failure on line 78 in src/day9.rs

View workflow job for this annotation

GitHub Actions / Check

mismatched types

Check failure on line 78 in src/day9.rs

View workflow job for this annotation

GitHub Actions / Lints

mismatched types
print!("{}", ".".repeat(blocks));
}
}
}
println!();

#[aoc(day9, part2)]
pub fn part2(input: &[Disk]) -> usize {
dbg!(input);
0
}

// #[aoc(day9, part2)]
// pub fn part2(input: &[Disk]) -> usize {
// // dbg!(input);
// 0
// }

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -49,8 +102,8 @@ mod tests {
assert_eq!(1, part1(&input_generator(INPUT)))
}

#[test]
fn test_part2() {
assert_eq!(1, part2(&input_generator(INPUT)))
}
// #[test]
// fn test_part2() {
// assert_eq!(1, part2(&input_generator(INPUT)))
// }
}

0 comments on commit 5d31475

Please sign in to comment.