feat: added day 25 part 1 and 2
All checks were successful
Build and run challenges / Challenge for day (1) (push) Successful in 5s
Build and run challenges / Challenge for day (10) (push) Successful in 3s
Build and run challenges / Challenge for day (14) (push) Successful in 3s
Build and run challenges / Challenge for day (15) (push) Successful in 3s
Build and run challenges / Challenge for day (16) (push) Successful in 3s
Build and run challenges / Challenge for day (20) (push) Successful in 3s
Build and run challenges / Challenge for day (11) (push) Successful in 3s
Build and run challenges / Challenge for day (12) (push) Successful in 3s
Build and run challenges / Challenge for day (13) (push) Successful in 3s
Build and run challenges / Challenge for day (17) (push) Successful in 3s
Build and run challenges / Challenge for day (18) (push) Successful in 4s
Build and run challenges / Challenge for day (19) (push) Successful in 3s
Build and run challenges / Challenge for day (2) (push) Successful in 3s
Build and run challenges / Challenge for day (22) (push) Successful in 4s
Build and run challenges / Challenge for day (23) (push) Successful in 4s
Build and run challenges / Challenge for day (25) (push) Successful in 3s
Build and run challenges / Challenge for day (4) (push) Successful in 5s
Build and run challenges / Challenge for day (3) (push) Successful in 11s
Build and run challenges / Challenge for day (6) (push) Successful in 5s
Build and run challenges / Challenge for day (7) (push) Successful in 4s
Build and run challenges / Challenge for day (8) (push) Successful in 3s
Build and run challenges / Challenge for day (9) (push) Successful in 3s
Build and run challenges / Challenge for day (21) (push) Successful in 3s
Build and run challenges / Challenge for day (24) (push) Successful in 4s
Build and run challenges / Challenge for day (5) (push) Successful in 5s
All checks were successful
Build and run challenges / Challenge for day (1) (push) Successful in 5s
Build and run challenges / Challenge for day (10) (push) Successful in 3s
Build and run challenges / Challenge for day (14) (push) Successful in 3s
Build and run challenges / Challenge for day (15) (push) Successful in 3s
Build and run challenges / Challenge for day (16) (push) Successful in 3s
Build and run challenges / Challenge for day (20) (push) Successful in 3s
Build and run challenges / Challenge for day (11) (push) Successful in 3s
Build and run challenges / Challenge for day (12) (push) Successful in 3s
Build and run challenges / Challenge for day (13) (push) Successful in 3s
Build and run challenges / Challenge for day (17) (push) Successful in 3s
Build and run challenges / Challenge for day (18) (push) Successful in 4s
Build and run challenges / Challenge for day (19) (push) Successful in 3s
Build and run challenges / Challenge for day (2) (push) Successful in 3s
Build and run challenges / Challenge for day (22) (push) Successful in 4s
Build and run challenges / Challenge for day (23) (push) Successful in 4s
Build and run challenges / Challenge for day (25) (push) Successful in 3s
Build and run challenges / Challenge for day (4) (push) Successful in 5s
Build and run challenges / Challenge for day (3) (push) Successful in 11s
Build and run challenges / Challenge for day (6) (push) Successful in 5s
Build and run challenges / Challenge for day (7) (push) Successful in 4s
Build and run challenges / Challenge for day (8) (push) Successful in 3s
Build and run challenges / Challenge for day (9) (push) Successful in 3s
Build and run challenges / Challenge for day (21) (push) Successful in 3s
Build and run challenges / Challenge for day (24) (push) Successful in 4s
Build and run challenges / Challenge for day (5) (push) Successful in 5s
Signed-off-by: Louis Vallat <contact@louis-vallat.dev>
This commit is contained in:
parent
093e724fa9
commit
8e7b848ec0
@ -11,7 +11,7 @@ jobs:
|
|||||||
name: Challenge for day
|
name: Challenge for day
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
day_number: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
|
day_number: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
|
||||||
runs-on: rust-bookworm
|
runs-on: rust-bookworm
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
|
6
day25/Cargo.toml
Normal file
6
day25/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "day25"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
68
day25/src/main.rs
Normal file
68
day25/src/main.rs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
use std::{env, fs};
|
||||||
|
|
||||||
|
fn read_input(path: &str) -> String {
|
||||||
|
fs::read_to_string(path).expect("Cannot read file.")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_input(input: &str) -> (Vec<Vec<u8>>, Vec<Vec<u8>>) {
|
||||||
|
let mut keys = Vec::new();
|
||||||
|
let mut locks = Vec::new();
|
||||||
|
|
||||||
|
let mut height = 0;
|
||||||
|
let mut x = vec![5; 5];
|
||||||
|
let mut is_key = false;
|
||||||
|
for line in input.lines() {
|
||||||
|
if line.is_empty() {
|
||||||
|
height = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if height == 0 {
|
||||||
|
is_key = line.starts_with(".");
|
||||||
|
} else if height == 6 {
|
||||||
|
if is_key {
|
||||||
|
keys.push(x.iter().map(|i| 5 - i).collect());
|
||||||
|
} else {
|
||||||
|
locks.push(x);
|
||||||
|
}
|
||||||
|
x = vec![5; 5];
|
||||||
|
} else {
|
||||||
|
for (i, c) in line.chars().enumerate() {
|
||||||
|
if x[i] == 5 && ((is_key && c == '#') || (!is_key && c == '.')) {
|
||||||
|
x[i] = height - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
height += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(keys, locks)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn part_1(keys: &Vec<Vec<u8>>, locks: &Vec<Vec<u8>>) -> u32 {
|
||||||
|
let mut combinations = 0;
|
||||||
|
for key in keys {
|
||||||
|
for lock in locks {
|
||||||
|
for i in 0..5 {
|
||||||
|
if key[i] + lock[i] > 5 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if i == 4 {
|
||||||
|
combinations += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
combinations
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
for arg in args.iter().skip(1) {
|
||||||
|
let input = read_input(&arg);
|
||||||
|
let (keys, locks) = parse_input(&input);
|
||||||
|
println!("[{}]", &arg);
|
||||||
|
println!("\t[Part 1] => Answer is '{}'.", part_1(&keys, &locks));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user