Compare commits
1 Commits
bb04979b45
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 523142f2f6 |
@@ -1,5 +1,12 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let key = get_key("./assets/day_1_input").unwrap();
|
||||||
|
println!("The key is: {key}");
|
||||||
|
let similarity = get_similarity("./assets/day_1_input");
|
||||||
|
println!("The similarity is: {similarity}");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_key(input: &str) -> Result<Key, ()> {
|
pub fn get_key(input: &str) -> Result<Key, ()> {
|
||||||
let mut key: Id = 0;
|
let mut key: Id = 0;
|
||||||
|
|
||||||
@@ -2,6 +2,11 @@ use utils::{calc_distance, read_report_list};
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let safe_report_count = check_reports_safety("./assets/day_2_reports_input");
|
||||||
|
println!("There are {safe_report_count} safe reports");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn check_reports_safety(input: &str) -> ReportSafety {
|
pub fn check_reports_safety(input: &str) -> ReportSafety {
|
||||||
let report_list = read_report_list(input);
|
let report_list = read_report_list(input);
|
||||||
|
|
||||||
@@ -3,6 +3,20 @@ use utils::read_instruction_input;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let multiplication_added_result = mull_it_over("./assets/day_3_instruction_input");
|
||||||
|
println!(
|
||||||
|
"The result of the sum of multiplications is {}",
|
||||||
|
multiplication_added_result
|
||||||
|
);
|
||||||
|
let conditional_multiplication_added_result =
|
||||||
|
mull_it_over_conditional("./assets/day_3_instruction_input");
|
||||||
|
println!(
|
||||||
|
"The result of the conditional sum of multiplications is {}",
|
||||||
|
conditional_multiplication_added_result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mull_it_over(input: &str) -> MulNumber {
|
pub fn mull_it_over(input: &str) -> MulNumber {
|
||||||
let instruction_input = read_instruction_input(input);
|
let instruction_input = read_instruction_input(input);
|
||||||
|
|
||||||
@@ -5,6 +5,12 @@ use super::*;
|
|||||||
const SEARCHED_WORD: &str = "XMAS";
|
const SEARCHED_WORD: &str = "XMAS";
|
||||||
const X_SEARCHED_WORD: &str = "MAS";
|
const X_SEARCHED_WORD: &str = "MAS";
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let (xmas_appearances, x_mas_appearances) = ceres_search("./assets/day_4_input");
|
||||||
|
println!("XMAS appears {} times", xmas_appearances);
|
||||||
|
println!("X-MAS appears {} times", x_mas_appearances);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ceres_search(input: &str) -> (XMASCount, XMASCount) {
|
pub fn ceres_search(input: &str) -> (XMASCount, XMASCount) {
|
||||||
let puzzle_matrix = read_ceres_puzzle_input(input);
|
let puzzle_matrix = read_ceres_puzzle_input(input);
|
||||||
|
|
||||||
@@ -2,6 +2,12 @@ use utils::read_rules_and_queue;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let (queue_mid_sum, fixed_queue_mid_sum) = mid_queue_sum("./assets/day_5_rules_queue_input");
|
||||||
|
println!("The update mid-queue-sum is {}", queue_mid_sum);
|
||||||
|
println!("The fixed update mid-queue-sum is {}", fixed_queue_mid_sum);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mid_queue_sum(input: &str) -> (u32, u32) {
|
pub fn mid_queue_sum(input: &str) -> (u32, u32) {
|
||||||
let (rules, queues) = read_rules_and_queue(input);
|
let (rules, queues) = read_rules_and_queue(input);
|
||||||
|
|
||||||
@@ -2,6 +2,13 @@ use std::collections::HashSet;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let (guard_position_count, loop_obstacle_count) =
|
||||||
|
guard_gallivant("./assets/day_6_guard_map_input");
|
||||||
|
println!("The guard will visit {} positions", guard_position_count);
|
||||||
|
println!("The guard would loop on {} positions", loop_obstacle_count);
|
||||||
|
}
|
||||||
|
|
||||||
impl Guard {
|
impl Guard {
|
||||||
fn step(&mut self, map: &FloorMap) -> IsGuardOut {
|
fn step(&mut self, map: &FloorMap) -> IsGuardOut {
|
||||||
let mut future_x = self.x;
|
let mut future_x = self.x;
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let calibration_result = bridge_repair("./assets/day_7_calibrations_input");
|
||||||
|
println!("The total calibration result is {}", calibration_result);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn bridge_repair(input: &str) -> CalibrationResult {
|
pub fn bridge_repair(input: &str) -> CalibrationResult {
|
||||||
let equation_vec = utils::read_calibration_equations(input);
|
let equation_vec = utils::read_calibration_equations(input);
|
||||||
let mut sum_result: CalibrationResult = 0;
|
let mut sum_result: CalibrationResult = 0;
|
||||||
@@ -4,41 +4,25 @@ use utils::read_antena_map_input;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let (antinode_count, antinode_count_any) =
|
||||||
|
resonant_collinearity("./assets/day_8_antena_map_input");
|
||||||
|
println!("The total antinode positions is {}", antinode_count);
|
||||||
|
println!(
|
||||||
|
"The total antinode positions in any grid is {}",
|
||||||
|
antinode_count_any
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn resonant_collinearity(input: &str) -> (AntinodeCount, AntinodeCount) {
|
pub fn resonant_collinearity(input: &str) -> (AntinodeCount, AntinodeCount) {
|
||||||
let (roof_map, antena_list) = read_antena_map_input(input);
|
let (roof_map, antena_list) = read_antena_map_input(input);
|
||||||
|
|
||||||
(
|
(
|
||||||
get_antinode_set_of_aligned_position(&antena_list, &roof_map).len(),
|
get_antinode_set_of_aligned_position(&antena_list, &roof_map).len(),
|
||||||
get_antinode_set_of_any_aligned_position(&antena_list, &roof_map).len(),
|
0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_antinode_set_of_any_aligned_position(
|
|
||||||
antena_list: &AntenaList,
|
|
||||||
map: &RoofMap,
|
|
||||||
) -> AntinodeList {
|
|
||||||
let mut antinode_list: AntinodeList = HashSet::new();
|
|
||||||
|
|
||||||
for antena in antena_list {
|
|
||||||
for complementary_antena in antena_list {
|
|
||||||
if antena != complementary_antena && antena.2 == complementary_antena.2 {
|
|
||||||
let distance_x = (antena.1 as i32 - complementary_antena.1 as i32).abs() as usize;
|
|
||||||
let distance_y = (antena.0 as i32 - complementary_antena.0 as i32).abs() as usize;
|
|
||||||
|
|
||||||
let mut count: usize = 0;
|
|
||||||
|
|
||||||
// loop {
|
|
||||||
// let test_x = distance_x * count;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// antinode_list.insert(pair);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
antinode_list
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_antinode_set_of_aligned_position(
|
pub fn get_antinode_set_of_aligned_position(
|
||||||
antena_list: &AntenaList,
|
antena_list: &AntenaList,
|
||||||
map: &RoofMap,
|
map: &RoofMap,
|
||||||
@@ -200,8 +184,8 @@ pub fn is_station_between(a: (usize, usize), b: (usize, usize), map: &RoofMap) -
|
|||||||
let x_diff = (a.1 as i32 - b.1 as i32).abs() as usize;
|
let x_diff = (a.1 as i32 - b.1 as i32).abs() as usize;
|
||||||
|
|
||||||
'check_diagonal: loop {
|
'check_diagonal: loop {
|
||||||
let mut next_x: i32 = 0;
|
let next_x: i32;
|
||||||
let mut next_y: i32 = 0;
|
let next_y: i32;
|
||||||
|
|
||||||
if a.1 > b.1 {
|
if a.1 > b.1 {
|
||||||
if a.0 > b.0 {
|
if a.0 > b.0 {
|
||||||
@@ -240,6 +224,7 @@ pub fn is_station_between(a: (usize, usize), b: (usize, usize), map: &RoofMap) -
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(_) = map[next_y as usize][next_x as usize] {
|
if let Some(_) = map[next_y as usize][next_x as usize] {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
use super::{utils::read_disk_map_input, DiskChecksum, DiskMap};
|
use super::{utils::read_disk_map_input, DiskChecksum, DiskMap};
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let disk_checksum = disk_fragmenter("./assets/day_9_disk_input");
|
||||||
|
println!("The disk checksum is {}", disk_checksum);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn disk_fragmenter(input: &str) -> DiskChecksum {
|
pub fn disk_fragmenter(input: &str) -> DiskChecksum {
|
||||||
let disk_map = read_disk_map_input(input);
|
let disk_map = read_disk_map_input(input);
|
||||||
|
|
||||||
@@ -2,6 +2,12 @@ use utils::read_trail_map_input;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let (trailhead_score, full_trailhead_score) = 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);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn hoof_it(input: &str) -> (usize, usize) {
|
pub fn hoof_it(input: &str) -> (usize, usize) {
|
||||||
let trail_map = read_trail_map_input(input);
|
let trail_map = read_trail_map_input(input);
|
||||||
|
|
||||||
@@ -1,5 +1,20 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let blink_count: usize = 25;
|
||||||
|
let stone_count = plutonian_pebbles("./assets/day_11_stone_arrangement_input", blink_count);
|
||||||
|
println!(
|
||||||
|
"The total of stones after {} is {}",
|
||||||
|
blink_count, stone_count
|
||||||
|
);
|
||||||
|
let blink_count: usize = 75;
|
||||||
|
let stone_count = plutonian_pebbles("./assets/day_11_stone_arrangement_input", blink_count);
|
||||||
|
println!(
|
||||||
|
"The total of stones after {} is {}",
|
||||||
|
blink_count, stone_count
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn plutonian_pebbles(input: &str, blink_count: usize) -> StoneCount {
|
pub fn plutonian_pebbles(input: &str, blink_count: usize) -> StoneCount {
|
||||||
let stone_list = utils::read_stone_arrangement(input);
|
let stone_list = utils::read_stone_arrangement(input);
|
||||||
|
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
pub fn today() {
|
||||||
|
let fence_cost = garden_groups("./assets/day_12_garden_input");
|
||||||
|
println!("The garden fence total cost is {}", fence_cost);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn garden_groups(input: &str) -> usize {
|
pub fn garden_groups(input: &str) -> usize {
|
||||||
let garden = utils::read_garden_arrangement_input(input);
|
let garden = utils::read_garden_arrangement_input(input);
|
||||||
|
|
||||||
@@ -1,105 +1,60 @@
|
|||||||
// mod sun_01;
|
mod day_01;
|
||||||
// mod mon_02;
|
mod day_02;
|
||||||
// mod tue_03;
|
mod day_03;
|
||||||
// mod wed_04;
|
mod day_04;
|
||||||
// mod thu_05;
|
mod day_05;
|
||||||
// mod fri_06;
|
mod day_06;
|
||||||
// mod sat_07;
|
mod day_07;
|
||||||
// mod sun_08;
|
mod day_08;
|
||||||
// mod mon_09;
|
mod day_09;
|
||||||
// mod tue_10;
|
mod day_10;
|
||||||
// mod wed_11;
|
mod day_11;
|
||||||
mod thu_12;
|
mod day_12;
|
||||||
mod types;
|
mod types;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use types::*;
|
use types::*;
|
||||||
|
|
||||||
pub fn today() {
|
pub fn today(day: u8) {
|
||||||
historian_hysteria()
|
match day {
|
||||||
}
|
1 => {
|
||||||
|
day_01::today();
|
||||||
pub fn historian_hysteria() {
|
}
|
||||||
// NOTE: previous days are commented to speed up (all the blame is on day 6)
|
2 => {
|
||||||
|
day_02::today();
|
||||||
// Sunday 01
|
}
|
||||||
// let key = sun_01::get_key("./assets/day_1_input").unwrap();
|
3 => {
|
||||||
// println!("The key is: {key}");
|
day_03::today();
|
||||||
// let similarity = sun_01::get_similarity("./assets/day_1_input");
|
}
|
||||||
// println!("The similarity is: {similarity}");
|
4 => {
|
||||||
|
day_04::today();
|
||||||
// Monday 02
|
}
|
||||||
// let safe_report_count = mon_02::check_reports_safety("./assets/day_2_reports_input");
|
5 => {
|
||||||
// println!("There are {safe_report_count} safe reports");
|
day_05::today();
|
||||||
|
}
|
||||||
// Tuesday 03
|
6 => {
|
||||||
// let multiplication_added_result = tue_03::mull_it_over("./assets/day_3_instruction_input");
|
day_06::today();
|
||||||
// println!(
|
}
|
||||||
// "The result of the sum of multiplications is {}",
|
7 => {
|
||||||
// multiplication_added_result
|
day_07::today();
|
||||||
// );
|
}
|
||||||
// let conditional_multiplication_added_result =
|
8 => {
|
||||||
// tue_03::mull_it_over_conditional("./assets/day_3_instruction_input");
|
day_08::today();
|
||||||
// println!(
|
}
|
||||||
// "The result of the conditional sum of multiplications is {}",
|
9 => {
|
||||||
// conditional_multiplication_added_result
|
day_09::today();
|
||||||
// );
|
}
|
||||||
|
10 => {
|
||||||
// Wednesday 04
|
day_10::today();
|
||||||
// let (xmas_appearances, x_mas_appearances) = wed_04::ceres_search("./assets/day_4_input");
|
}
|
||||||
// println!("XMAS appears {} times", xmas_appearances);
|
11 => {
|
||||||
// println!("X-MAS appears {} times", x_mas_appearances);
|
day_11::today();
|
||||||
|
}
|
||||||
// Thursday 05
|
12 => {
|
||||||
// let (queue_mid_sum, fixed_queue_mid_sum) =
|
day_12::today();
|
||||||
// thu_05::mid_queue_sum("./assets/day_5_rules_queue_input");
|
}
|
||||||
// println!("The update mid-queue-sum is {}", queue_mid_sum);
|
_ => {
|
||||||
// println!("The fixed update mid-queue-sum is {}", fixed_queue_mid_sum);
|
println!("Not a valid day.");
|
||||||
|
}
|
||||||
// Friday 06
|
}
|
||||||
// let (guard_position_count, loop_obstacle_count) =
|
|
||||||
// fri_06::guard_gallivant("./assets/day_6_guard_map_input");
|
|
||||||
// println!("The guard will visit {} positions", guard_position_count);
|
|
||||||
// println!("The guard would loop on {} positions", loop_obstacle_count);
|
|
||||||
|
|
||||||
// Saturday 07
|
|
||||||
// let calibration_result = sat_07::bridge_repair("./assets/day_7_calibrations_input");
|
|
||||||
// println!("The total calibration result is {}", calibration_result);
|
|
||||||
|
|
||||||
// Sunday 08
|
|
||||||
// let (antinode_count, antinode_count_any) =
|
|
||||||
// sun_08::resonant_collinearity("./assets/day_8_antena_map_input");
|
|
||||||
// println!("The total antinode positions is {}", antinode_count);
|
|
||||||
// println!(
|
|
||||||
// "The total antinode positions in any grid is {}",
|
|
||||||
// antinode_count_any
|
|
||||||
// );
|
|
||||||
|
|
||||||
// Monday 09
|
|
||||||
// let disk_checksum = mon_09::disk_fragmenter("./assets/day_9_disk_input");
|
|
||||||
// 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 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
|
|
||||||
// );
|
|
||||||
// let blink_count: usize = 75;
|
|
||||||
// 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
|
|
||||||
// );
|
|
||||||
|
|
||||||
// Thursday 12
|
|
||||||
let fence_cost = thu_12::garden_groups("./assets/day_12_garden_input");
|
|
||||||
println!("The garden fence total cost is {}", fence_cost);
|
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/main.rs
15
src/main.rs
@@ -1,7 +1,18 @@
|
|||||||
#![allow(dead_code)]
|
use std::env;
|
||||||
|
|
||||||
|
// #![allow(dead_code)]
|
||||||
mod advent_of_code;
|
mod advent_of_code;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
advent_of_code::today();
|
let args: Vec<String> = env::args().collect();
|
||||||
|
println!("<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>");
|
||||||
|
println!(">>> Welcome to advent of code 2024 <<<");
|
||||||
|
println!("<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>");
|
||||||
|
if args.len() == 2 {
|
||||||
|
let day: u8 = args[1].parse().expect("Not a valid day.");
|
||||||
|
advent_of_code::today(day);
|
||||||
|
} else {
|
||||||
|
println!("Tell me a day!")
|
||||||
|
}
|
||||||
println!("Happy new year!");
|
println!("Happy new year!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user