day_9: init
This commit is contained in:
@@ -11,7 +11,7 @@ https://adventofcode.com/2024
|
|||||||
| 06 | Guard Gallivant | :pushpin: | :pushpin: | 2D navigation |
|
| 06 | Guard Gallivant | :pushpin: | :pushpin: | 2D navigation |
|
||||||
| 07 | Bridge Repair | :pushpin: | :pushpin: | Equation parsing |
|
| 07 | Bridge Repair | :pushpin: | :pushpin: | Equation parsing |
|
||||||
| 08 | Resonant Collinearity | :pushpin: | | Matrix exploration |
|
| 08 | Resonant Collinearity | :pushpin: | | Matrix exploration |
|
||||||
| 09 | | | | |
|
| 09 | Disk fragmenter | | | |
|
||||||
| 10 | | | | |
|
| 10 | | | | |
|
||||||
| 11 | | | | |
|
| 11 | | | | |
|
||||||
| 12 | | | | |
|
| 12 | | | | |
|
||||||
|
|||||||
1
assets/day_9_disk_input
Normal file
1
assets/day_9_disk_input
Normal file
@@ -0,0 +1 @@
|
|||||||
|
2333133121414131402
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
// mod fri_06;
|
|
||||||
// mod mon_02;
|
|
||||||
// mod sun_01;
|
// mod sun_01;
|
||||||
// mod thu_05;
|
// mod mon_02;
|
||||||
// mod tue_03;
|
// mod tue_03;
|
||||||
// mod wed_04;
|
// mod wed_04;
|
||||||
|
// mod thu_05;
|
||||||
|
// mod fri_06;
|
||||||
// mod sat_07;
|
// mod sat_07;
|
||||||
mod sun_08;
|
// mod sun_08;
|
||||||
|
mod mon_09;
|
||||||
mod types;
|
mod types;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ pub fn today() {
|
|||||||
|
|
||||||
pub fn historian_hysteria() {
|
pub fn historian_hysteria() {
|
||||||
// NOTE: previous days are commented to speed up (all the blame is on day 6)
|
// NOTE: previous days are commented to speed up (all the blame is on day 6)
|
||||||
|
|
||||||
// Sunday 01
|
// Sunday 01
|
||||||
// let key = sun_01::get_key("./assets/day_1_input").unwrap();
|
// let key = sun_01::get_key("./assets/day_1_input").unwrap();
|
||||||
// println!("The key is: {key}");
|
// println!("The key is: {key}");
|
||||||
@@ -62,11 +64,14 @@ pub fn historian_hysteria() {
|
|||||||
// println!("The total calibration result is {}", calibration_result);
|
// println!("The total calibration result is {}", calibration_result);
|
||||||
|
|
||||||
// Sunday 08
|
// Sunday 08
|
||||||
let (antinode_count, antinode_count_any) =
|
// let (antinode_count, antinode_count_any) =
|
||||||
sun_08::resonant_collinearity("./assets/day_8_antena_map_input");
|
// sun_08::resonant_collinearity("./assets/day_8_antena_map_input");
|
||||||
println!("The total antinode positions is {}", antinode_count);
|
// println!("The total antinode positions is {}", antinode_count);
|
||||||
println!(
|
// println!(
|
||||||
"The total antinode positions in any grid is {}",
|
// "The total antinode positions in any grid is {}",
|
||||||
antinode_count_any
|
// antinode_count_any
|
||||||
);
|
// );
|
||||||
|
|
||||||
|
// Monday 09
|
||||||
|
let disk_checksum = mon_09::disk_fragmenter("./assets/day_9_disk_input");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
use super::{utils::read_disk_map_input, DiskMap};
|
||||||
|
|
||||||
|
pub fn disk_fragmenter(input: &str) -> usize {
|
||||||
|
let disk_map = read_disk_map_input(input);
|
||||||
|
|
||||||
|
let organized_disk_map = organize_disk_map(&disk_map);
|
||||||
|
println!("{:?}", disk_map);
|
||||||
|
println!("{:?}", organized_disk_map);
|
||||||
|
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn organize_disk_map(disk_map: &DiskMap) -> DiskMap {
|
||||||
|
let organized_disk_map: DiskMap = vec![];
|
||||||
|
|
||||||
|
for block in disk_map {}
|
||||||
|
|
||||||
|
organized_disk_map
|
||||||
|
}
|
||||||
|
|||||||
@@ -71,3 +71,7 @@ pub type AntenaList = Vec<Antena>;
|
|||||||
pub type AntinodeCount = usize;
|
pub type AntinodeCount = usize;
|
||||||
pub type Antinode = (usize, usize);
|
pub type Antinode = (usize, usize);
|
||||||
pub type AntinodeList = HashSet<Antinode>;
|
pub type AntinodeList = HashSet<Antinode>;
|
||||||
|
|
||||||
|
// Disk fragmenter
|
||||||
|
pub type Block = Option<usize>;
|
||||||
|
pub type DiskMap = Vec<Block>;
|
||||||
|
|||||||
@@ -164,6 +164,29 @@ pub fn read_antena_map_input(input: &str) -> (RoofMap, AntenaList) {
|
|||||||
(roof_map, antena_list)
|
(roof_map, antena_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_disk_map_input(input: &str) -> DiskMap {
|
||||||
|
let mut disk_map: DiskMap = vec![];
|
||||||
|
let raw_map = read_to_string(input).unwrap();
|
||||||
|
|
||||||
|
let mut id: usize = 0;
|
||||||
|
for (digit_index, char_digit) in raw_map.chars().enumerate() {
|
||||||
|
if let Some(digit) = char_digit.to_digit(10u32) {
|
||||||
|
for _ in 0..digit {
|
||||||
|
if digit_index % 2 == 0 {
|
||||||
|
disk_map.push(Some(id));
|
||||||
|
} else {
|
||||||
|
disk_map.push(None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if digit_index % 2 == 0 {
|
||||||
|
id += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
disk_map
|
||||||
|
}
|
||||||
|
|
||||||
pub fn calc_distance<T>(num_1: T, num_2: T) -> T
|
pub fn calc_distance<T>(num_1: T, num_2: T) -> T
|
||||||
where
|
where
|
||||||
T: PartialOrd + Sub<Output = T>,
|
T: PartialOrd + Sub<Output = T>,
|
||||||
|
|||||||
Reference in New Issue
Block a user