day_11: part 1 done
This commit is contained in:
@@ -13,7 +13,7 @@ https://adventofcode.com/2024
|
||||
| 08 | Resonant Collinearity | :pushpin: | | Matrix exploration |
|
||||
| 09 | Disk fragmenter | :pushpin: | | Array indexing |
|
||||
| 10 | Hoof It | :pushpin: | :pushpin: | Path finding |
|
||||
| 11 | | | | |
|
||||
| 11 | Plutonian Pebbles | :pushpin: | | Array and digit manipulation |
|
||||
| 12 | | | | |
|
||||
| 13 | | | | |
|
||||
| 14 | | | | |
|
||||
|
||||
1
assets/day_11_stone_arrangement_input
Normal file
1
assets/day_11_stone_arrangement_input
Normal file
@@ -0,0 +1 @@
|
||||
2 77706 5847 9258441 0 741 883933 12
|
||||
@@ -7,9 +7,10 @@
|
||||
// mod sat_07;
|
||||
// mod sun_08;
|
||||
// mod mon_09;
|
||||
mod tue_10;
|
||||
// mod tue_10;
|
||||
mod types;
|
||||
mod utils;
|
||||
mod wed_11;
|
||||
|
||||
use types::*;
|
||||
|
||||
@@ -78,8 +79,15 @@ pub fn historian_hysteria() {
|
||||
// println!("The disk checksum is {}", disk_checksum);
|
||||
|
||||
// Tuesday 10
|
||||
let (trailhead_score, full_trailhead_score) =
|
||||
tue_10::hoof_it("./assets/day_10_trail_map_input");
|
||||
println!("The trail head sum score is {}", trailhead_score);
|
||||
println!("The full trail head sum score is {}", full_trailhead_score);
|
||||
// let (trailhead_score, full_trailhead_score) =
|
||||
// tue_10::hoof_it("./assets/day_10_trail_map_input");
|
||||
// println!("The trail head sum score is {}", trailhead_score);
|
||||
// println!("The full trail head sum score is {}", full_trailhead_score);
|
||||
let blink_count: usize = 25;
|
||||
let stone_count =
|
||||
wed_11::plutonian_pebbles("./assets/day_11_stone_arrangement_input", blink_count);
|
||||
println!(
|
||||
"The total of stones after {} is {}",
|
||||
blink_count, stone_count
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,3 +81,8 @@ pub type DiskChecksum = usize;
|
||||
pub type TrailScore = usize;
|
||||
pub type TrailPosition = usize;
|
||||
pub type TrailMap = Vec<Vec<TrailPosition>>;
|
||||
|
||||
// Plutonian Pebbles
|
||||
pub type StoneCount = usize;
|
||||
pub type Stone = usize;
|
||||
pub type StoneList = Vec<Stone>;
|
||||
|
||||
@@ -206,6 +206,18 @@ pub fn read_trail_map_input(input: &str) -> TrailMap {
|
||||
trail_map
|
||||
}
|
||||
|
||||
pub fn read_stone_arrangement(input: &str) -> StoneList {
|
||||
let mut stone_list: StoneList = vec![];
|
||||
|
||||
for line in read_to_string(input).unwrap().lines() {
|
||||
for number in line.split(" ") {
|
||||
stone_list.push(number.parse::<Stone>().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
stone_list
|
||||
}
|
||||
|
||||
pub fn calc_distance<T>(num_1: T, num_2: T) -> T
|
||||
where
|
||||
T: PartialOrd + Sub<Output = T>,
|
||||
|
||||
53
src/advent_of_code/wed_11.rs
Normal file
53
src/advent_of_code/wed_11.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use super::*;
|
||||
|
||||
pub fn plutonian_pebbles(input: &str, blink_count: usize) -> StoneCount {
|
||||
let stone_list = utils::read_stone_arrangement(input);
|
||||
|
||||
let stone_list = apply_rules(stone_list, blink_count);
|
||||
|
||||
stone_list.len()
|
||||
}
|
||||
|
||||
fn apply_rules(stone_list: StoneList, blink_count: usize) -> StoneList {
|
||||
let mut new_stone_list = stone_list.clone();
|
||||
|
||||
for _ in 0..blink_count {
|
||||
new_stone_list = blink(new_stone_list);
|
||||
}
|
||||
|
||||
new_stone_list
|
||||
}
|
||||
|
||||
fn blink(stone_list: StoneList) -> StoneList {
|
||||
let mut new_stone_list: StoneList = vec![];
|
||||
|
||||
const STONE_MULTIPLIER: usize = 2024;
|
||||
for stone in stone_list {
|
||||
match stone {
|
||||
0 => {
|
||||
new_stone_list.push(1);
|
||||
}
|
||||
stone if stone.to_string().len() % 2 == 0 => {
|
||||
let (left, right) = split_num(stone);
|
||||
new_stone_list.push(left);
|
||||
new_stone_list.push(right);
|
||||
}
|
||||
_ => {
|
||||
new_stone_list.push(stone * STONE_MULTIPLIER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new_stone_list
|
||||
}
|
||||
|
||||
fn split_num(num: Stone) -> (Stone, Stone) {
|
||||
let split_index = num.to_string().len() / 2;
|
||||
let binding = num.to_string();
|
||||
let (first, second) = binding.split_at(split_index);
|
||||
|
||||
(
|
||||
first.parse::<Stone>().unwrap(),
|
||||
second.parse::<Stone>().unwrap(),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user