Add 2024 Quests 17 - 19
This commit is contained in:
parent
5d1320bec9
commit
6632529d20
27 changed files with 1613 additions and 0 deletions
6
2024/day17_galactic_geometry/Cargo.toml
Normal file
6
2024/day17_galactic_geometry/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "day17_galactic_geometry"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
59
2024/day17_galactic_geometry/challenge.txt
Normal file
59
2024/day17_galactic_geometry/challenge.txt
Normal file
|
@ -0,0 +1,59 @@
|
|||
Part I
|
||||
|
||||
Stars are an excellent form of navigation system. Knowledge of them allows travellers to determine the exact locations of places both on land and at sea. Of course, the Knights of the Order possess extensive knowledge on this subject and can effortlessly identify all constellations. The best knights not only have physical strength but also intellectual prowess, so the Order is seeking to test the contestants' abilities in celestial cartography.
|
||||
First, you need to know how to measure the distance between two stars. Each star has coordinates that define its position in space. To calculate the distance between two stars based on their coordinates, take the absolute difference of their X coordinates and the absolute difference of their Y coordinates. Then sum these differences. For example, if you have two stars with coordinates at 2, 4 and at 7, 3 , the distance between them is calculated as abs(2 - 7) + abs(4 - 3) = 5 + 1 = 6 .
|
||||
This method of measurement is known as the algorithm from Manhattan's Realm.
|
||||
A constellation is a group of stars that forms a single structure such that the sum of all distances between connected stars is as low as possible. There are also as few connections as necessary to maintain connectivity.
|
||||
Once the stars are connected in this manner, the size of the constellation is determined, which is the number of stars forming the constellation combined with the sum of the distances between connected stars.
|
||||
The sky is exceptionally clear and dark tonight. These are ideal conditions for the tournament's astronomy competition. Each participant receives a fragment of the sky to analyse (your notes), featuring several stars. Your goal is to create a constellation from these stars and determine its size.
|
||||
Example based on the following notes:
|
||||
*...*
|
||||
..*..
|
||||
.....
|
||||
.....
|
||||
*.*..
|
||||
There are five stars in the sample part of the sky, so let's use numbers to identify them more easily and note their coordinates, assuming the bottom left corner has coordinates 1, 1 :
|
||||
1...2
|
||||
..3..
|
||||
.....
|
||||
.....
|
||||
4.5..
|
||||
|
||||
Star Coordinates
|
||||
1 1,5
|
||||
2 5,5
|
||||
3 3,4
|
||||
4 1,1
|
||||
5 3,1
|
||||
Creating a constellation from this group may look as follows:
|
||||
|
||||
There are four connections with the distances as below:
|
||||
Connected Stars Distance
|
||||
1 and 3 3
|
||||
2 and 3 3
|
||||
3 and 5 3
|
||||
4 and 5 2
|
||||
The constellation contains 5 stars, and the sum of all connections between them is 11, so the final size is equal to 5 + 11 = 16.
|
||||
There are many other ways to connect the stars into a single structure; however, the one above results in the lowest possible size for this example, so only this is considered an actual constellation.
|
||||
What is the size of the constellation created from all the stars on your part of the sky?
|
||||
|
||||
Part II
|
||||
|
||||
The second round of the task is exactly the same. The only changes are the size of the sky you need to analyse and the number of stars to connect into a single constellation. However, your method is very well prepared for slightly larger notes!
|
||||
What is the size of the constellation created from all the stars on your part of the sky?
|
||||
|
||||
Part III
|
||||
|
||||
There is also a special type of constellation called a brilliant constellation. They function similarly to regular constellations, but the distance between connected stars must be less than 6. If two stars or groups of stars are further apart, they are considered as separate brilliant constellations.
|
||||
The final round involves finding brilliant constellations on the given fragment of the sky. Identify the three largest brilliant constellations and multiply their sizes to get the final answer.
|
||||
Example based on the following notes:
|
||||
.......................................
|
||||
..*.......*...*.....*...*......**.**...
|
||||
....*.................*.......*..*..*..
|
||||
..*.........*.......*...*.....*.....*..
|
||||
......................*........*...*...
|
||||
..*.*.....*...*.....*...*........*.....
|
||||
.......................................
|
||||
There are 4 brilliant constellations with sizes (from the left): 14, 21, 24, and 31.
|
||||
Multiplying the three largest sizes gives 31 * 24 * 21 = 15624.
|
||||
Find the three largest brilliant constellations on your new part of the sky. What is the result of multiplying their sizes?
|
210
2024/day17_galactic_geometry/src/lib.rs
Normal file
210
2024/day17_galactic_geometry/src/lib.rs
Normal file
|
@ -0,0 +1,210 @@
|
|||
use core::fmt::Display;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ParseError {
|
||||
NoStars,
|
||||
}
|
||||
|
||||
impl Display for ParseError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::NoStars => write!(f, "No Stars found in input. Stars should be represented by \'*\'."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Star {
|
||||
x: usize,
|
||||
y: usize,
|
||||
}
|
||||
|
||||
impl Star {
|
||||
fn distance_to(&self, other: &Self) -> usize {
|
||||
self.x.abs_diff(other.x) + self.y.abs_diff(other.y)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Constellation {
|
||||
stars: usize,
|
||||
distance: usize,
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for Constellation {
|
||||
type Error = ParseError;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
// Initialize the stars without connections
|
||||
let stars: Vec<Star> = value
|
||||
.lines()
|
||||
.enumerate()
|
||||
.flat_map(|(y, line)| line
|
||||
.chars()
|
||||
.enumerate()
|
||||
.filter(|(_x, c)| *c == '*')
|
||||
.map(|(x, _c)| Star { x, y, })
|
||||
.collect::<Vec<_>>()
|
||||
).collect();
|
||||
|
||||
if stars.is_empty() {
|
||||
return Err(Self::Error::NoStars);
|
||||
}
|
||||
|
||||
// Find connections using Prim's algorithm
|
||||
let mut distances = vec![vec![0; stars.len()]; stars.len()];
|
||||
stars.iter().enumerate().for_each(|(l_idx, l_star)| stars.iter().enumerate().skip(l_idx+1).for_each(|(r_idx, r_star)| {
|
||||
let distance = l_star.distance_to(r_star);
|
||||
distances[l_idx][r_idx] = distance;
|
||||
distances[r_idx][l_idx] = distance;
|
||||
}));
|
||||
let mut conncections = vec![Vec::new(); stars.len()];
|
||||
let (first_idx, dist) = distances[0].iter().enumerate().skip(1).min_by_key(|(_idx, dist)| *dist).unwrap();
|
||||
conncections[0].push(first_idx);
|
||||
conncections[first_idx].push(0);
|
||||
let mut distance = *dist;
|
||||
|
||||
loop {
|
||||
let missing: Vec<_> = conncections.iter().enumerate().filter(|(_idx, conns)| conns.is_empty()).map(|(idx, _conns)| idx).collect();
|
||||
if missing.is_empty() {
|
||||
break;
|
||||
}
|
||||
let (next_l, (next_r, dist)) = missing
|
||||
.iter()
|
||||
.map(|l_idx| (*l_idx, distances[*l_idx]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(r_idx, _dist)| missing.binary_search(r_idx).is_err())
|
||||
.min_by_key(|(_r_idx, dist)| **dist)
|
||||
.unwrap_or((0, &usize::MAX)))
|
||||
).min_by_key(|(_l_idx, (_r_idx, dist))| **dist)
|
||||
.unwrap();
|
||||
conncections[next_l].push(next_r);
|
||||
conncections[next_r].push(next_l);
|
||||
distance += *dist;
|
||||
}
|
||||
|
||||
Ok(Self { stars: stars.len(), distance, })
|
||||
}
|
||||
}
|
||||
|
||||
impl Constellation {
|
||||
fn size(&self) -> usize {
|
||||
self.stars + self.distance
|
||||
}
|
||||
}
|
||||
|
||||
struct BrilliantConstellations {
|
||||
constellations: Vec<Constellation>
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for BrilliantConstellations {
|
||||
type Error = ParseError;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
// Initialize the stars without connections
|
||||
let stars: Vec<_> = value
|
||||
.lines()
|
||||
.enumerate()
|
||||
.flat_map(|(y, line)| line
|
||||
.chars()
|
||||
.enumerate()
|
||||
.filter(|(_x, c)| *c == '*')
|
||||
.map(|(x, _c)| Star { x, y, })
|
||||
.collect::<Vec<_>>()
|
||||
).collect();
|
||||
|
||||
if stars.is_empty() {
|
||||
return Err(Self::Error::NoStars);
|
||||
}
|
||||
|
||||
// Find connections using Prim's algorithm
|
||||
let mut distances = vec![vec![0; stars.len()]; stars.len()];
|
||||
stars.iter().enumerate().for_each(|(l_idx, l_star)| stars.iter().enumerate().skip(l_idx+1).for_each(|(r_idx, r_star)| {
|
||||
let distance = l_star.distance_to(r_star);
|
||||
distances[l_idx][r_idx] = distance;
|
||||
distances[r_idx][l_idx] = distance;
|
||||
}));
|
||||
let mut constellations: Vec<(Vec<usize>, usize)> = Vec::new();
|
||||
for first_idx in 0..stars.len() {
|
||||
if constellations.iter().any(|(cons, _d)| cons.contains(&first_idx)) {
|
||||
continue;
|
||||
}
|
||||
if let Some((next_idx, dist)) = distances[first_idx]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(idx, dist)| **dist < 6 &&
|
||||
*idx != first_idx &&
|
||||
!constellations.iter().any(|(cons, _d)| cons.contains(idx)))
|
||||
.min_by_key(|(_idx, dist)| **dist)
|
||||
{
|
||||
let mut this_cons = Vec::from([first_idx, next_idx]);
|
||||
let mut this_len = *dist;
|
||||
while let Some((other, dist)) = this_cons
|
||||
.iter()
|
||||
.flat_map(|seen| distances[*seen]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(new, dist)| **dist < 6 &&
|
||||
!this_cons.contains(new) &&
|
||||
!constellations.iter().any(|(cons, _d)| cons.contains(new))
|
||||
))
|
||||
.min_by_key(|(_idx, dist)| **dist)
|
||||
{
|
||||
this_cons.push(other);
|
||||
this_len += dist;
|
||||
}
|
||||
constellations.push((this_cons, this_len));
|
||||
|
||||
} else {
|
||||
constellations.push((Vec::from([first_idx]), 0));
|
||||
}
|
||||
}
|
||||
Ok(Self { constellations: constellations.iter().map(|(stars, dist)| Constellation{ stars: stars.len(), distance: *dist }).collect(), })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(input: &str, part: usize) -> Result<usize, ParseError> {
|
||||
// let items: Vec<_> = input.lines().map(::try_from).collect::<Result<Vec<_>, _>>()?;
|
||||
match part {
|
||||
1 | 2 => {
|
||||
let constellation = Constellation::try_from(input)?;
|
||||
Ok(constellation.size())
|
||||
},
|
||||
3 => {
|
||||
let brilliant_constellations = BrilliantConstellations::try_from(input)?;
|
||||
let mut sizes: Vec<_> = brilliant_constellations.constellations.iter().map(Constellation::size).collect();
|
||||
sizes.sort_by_key(|s| usize::MAX - s);
|
||||
Ok(sizes.iter().take(3).product())
|
||||
},
|
||||
_ => panic!("Illegal part number"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs::read_to_string;
|
||||
|
||||
fn read_file(name: &str) -> String {
|
||||
read_to_string(name).expect(&format!("Unable to read file: {name}")[..]).trim().to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sample() {
|
||||
let expected = [16, 16, 15624];
|
||||
for part in 1..=expected.len() {
|
||||
let sample_input = read_file(&format!("tests/sample{part}"));
|
||||
assert_eq!(run(&sample_input, part), Ok(expected[part-1]));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_challenge() {
|
||||
let expected = [135, 1244, 3818228112];
|
||||
for part in 1..=expected.len() {
|
||||
let challenge_input = read_file(&format!("tests/challenge{part}"));
|
||||
assert_eq!(run(&challenge_input, part), Ok(expected[part-1]));
|
||||
}
|
||||
}
|
||||
}
|
17
2024/day17_galactic_geometry/tests/challenge1
Normal file
17
2024/day17_galactic_geometry/tests/challenge1
Normal file
|
@ -0,0 +1,17 @@
|
|||
*.........*.........*
|
||||
.....................
|
||||
..*.........*...*....
|
||||
.....................
|
||||
......*....*......*..
|
||||
.....................
|
||||
........*...*........
|
||||
.....................
|
||||
*.....*...*...*.....*
|
||||
.....................
|
||||
........*...*........
|
||||
.....................
|
||||
...*....*...*........
|
||||
.....................
|
||||
....*...*....*.......
|
||||
.....................
|
||||
*.........*.........*
|
51
2024/day17_galactic_geometry/tests/challenge2
Normal file
51
2024/day17_galactic_geometry/tests/challenge2
Normal file
|
@ -0,0 +1,51 @@
|
|||
*........................................*...........*..........*....*.................*.....*......*
|
||||
.......*..*.............................................................*.......*....................
|
||||
...*...................*..*.................................*........................................
|
||||
.....................*...*.......*......*...........*.....*......*.................................*.
|
||||
.*..................................*.................................*..............................
|
||||
.......*...................*...*.*..................*................................................
|
||||
..........................................*.....................*.............*............*...*.....
|
||||
...............*..*..............*........................*...........*..............................
|
||||
...........................................................................*.........................
|
||||
.......................................*.....................*...........................*........*..
|
||||
.........................................................................................*...........
|
||||
..........*.....................*.*............*............................................*........
|
||||
............................*...................*....................................................
|
||||
..........*........*......................*............*.......................................*.....
|
||||
...............*..........................*..........................................................
|
||||
......*..............*........*........*...*.....*.......*..........*.......*........................
|
||||
...........................................................*...................................*.....
|
||||
..*...*.......................*....*.*................*....................*..*....*.....*.....*.*...
|
||||
.........*.*...........................*......*...........................*......*...........*.......
|
||||
.......*..............................*..*.................*.............................*...........
|
||||
.*.........*.....................*.*..................**.....*....*..*.*.............*.*..**.........
|
||||
....*.......................*..*..................*.....................................*............
|
||||
.......................................*..............*.............................*.*..............
|
||||
...................................*................................*....*...........................
|
||||
...............*............*.....................*..........................*.......................
|
||||
............................*....................***............*......................*.............
|
||||
.*......*..*....*.................................*....*.....................*...............*.*.....
|
||||
........................................................*...*........................................
|
||||
...................................................*...........*.................................*..*
|
||||
......*......*.............................................................*.........**..............
|
||||
......................................................*...*......*......*..................*.........
|
||||
........................*..............*....*..........*............................*................
|
||||
.....................*.............*..*..............*.*..................................*.......**.
|
||||
............*....*...*..................*.......................................*....................
|
||||
..............................*....................*...............................*.................
|
||||
.........*............................*........*..*..................*..............................*
|
||||
................*...................................................*.............*..................
|
||||
.....................*............*.............*...*....................*...........................
|
||||
...................*...............*............................*.................*............*..*..
|
||||
.................*............................*.........*......*......*..*.....*..*..............*...
|
||||
..........................................*.......................*..*.................*.............
|
||||
**.....................................................*..................*..........................
|
||||
.........*.........*.......................*...................*............*...............*........
|
||||
..............*...............*................................*......*..............................
|
||||
.................*.......*..............*.......................*...........................**.......
|
||||
................*....................*......*..............*...............................*.........
|
||||
...........*....*..........*.*...............................................*.......................
|
||||
.......................*.....................*.......*................*.....................*........
|
||||
.........*.............*.................................*.*................*........................
|
||||
....*................*...............*.............................................................**
|
||||
*...............*.......*...................*.......*............................*..........*......**
|
151
2024/day17_galactic_geometry/tests/challenge3
Normal file
151
2024/day17_galactic_geometry/tests/challenge3
Normal file
|
@ -0,0 +1,151 @@
|
|||
*....*................*.............................*........*..............*..........*............*...*..........*.............*............*..............*.........*...*......*.................*...*
|
||||
..............................*.......*.............*.........................................................................................*...*................*.....*.....*.........*...............
|
||||
..............................*..........*....................*....*.................................*...........*.......*.................*.........................................*...................
|
||||
...................*...*.................*..*........................*..............*............*..............................................*..................*..*.*..*...........*.....*...........
|
||||
........*.......................*............................*..............*.....*.........*..........*.*.....*............*.............*..*...........................................*...............
|
||||
.............*.................*.............................*.................*...............................*......................*.................................*.....*..........*...............
|
||||
.................................**..............*.........................*...................................................*.......*.................................*.*.................*...........
|
||||
.......*.........*........*...................................*..................................*.............*..................*.*......................*................*.......*....................
|
||||
.*..............................*.....*.............................*.*...............*....*.................................................................*..........*.........*..........*........*..
|
||||
...*.......................*......................................*....*.*....................*.*.......*.........................................................*.............*........................
|
||||
....*.........................................................................*............*...........................................*.................................................................
|
||||
......*.......................*.......**.......*..*.......*..............*...........................*........*.**.......................................*........**......*...............*..............
|
||||
.....................*...................*..................**...............***..........*.....................................................................*........................*...............
|
||||
............*...............*.......*.....*..*....................*....**...................*.................................*................**..........*........*.*.....*......*.....................
|
||||
................*................................................................*..................*...................................................*...............................................*
|
||||
.......................*..*.......*..*...*.*.......*.............*.*..........*.*...................*.........*....*.......................**.*..............*.......***......*..........................
|
||||
....................*.........................*.*..................*...............*.**..................................................*..............................*..........*.....................
|
||||
.*...................*...*.....**......*.*....*....*.....*....*..........................*..........*...........................*.......*.....*................*........*......*.......*.................
|
||||
........................................*..............**............*........*.*......*.............*...........................*....*....*............*.....*..*......*......*......*....*.............
|
||||
....*..................*.......*...*...*...........................................*......................*.....................................*................*.......*....*..*...............*.......
|
||||
............*.*........*............................................................*.........*...................................*....*..................*..........................*.....*....*..*.....
|
||||
......................*......*.......*.............................................**.........................................*................***.................*.....*.*..*...*......................
|
||||
.......................................*..................*.............*............................*.*..............*.................*..*..................*.................................*.*......
|
||||
*...................**.*....*......*...............*...........................*...........................................................................*...*.....**.....*.......*.*.............*....
|
||||
......*...............*.**...................................................................................*........................*............*..*..................................................
|
||||
............*.....**......*.*.....*.............*...........................*..............................*............*.............................................*.......*......*........*.........*
|
||||
................................................................*.....*............................................*..............................................*..........................**..........
|
||||
..*...............*...*..*......*........*.........................*....*...............*.*.....*....................................................*..................*......*......*..................
|
||||
....*..................*...............*............................*.............................*.......*....*...............................................................*.........................
|
||||
...*.............*......*......*.................................................................................*.....*....................*........................*...*......*......*............*....
|
||||
......................*..................................*.........*................*...*...*.......*....................................*..*.......*...........................................*........
|
||||
................*......*......*......................*....*.........*.*............................................*..*...........**.........................*...*....*...*......*......*................
|
||||
..................................*........................................................*...................*.................................................*..................*....................
|
||||
..........*.*..*......*.....*..................................................*.........*....*...................................*.............*...........................*.....*......*...............
|
||||
..............*...............................*......*...........*...................**........................................................*.......*.............*....*.....*.*......................
|
||||
*...........*.*...*.*.*....*.*...........................*...*..*...**..............*..............................*............*........................*...........*.......*......**....*.*....*.......
|
||||
....*....................*.............................................................*.......*......*...*...................**........*..............................*................*...........*..*.
|
||||
.............*..**..*...*.*................................*...*...........*...............**.........................*.........*......................*...*.....*......*.....*....**....*.*.....*.......
|
||||
......*......*.....................................................*....................................................*.....................*.*...............*.*...........*.................*........
|
||||
.*..........*......*.....*....................*.......*....................*..........*..........................................*..................*..........................*.*...*......*............
|
||||
.....*................*.....................................................*..................*.........................................*..*........*..........................................*........
|
||||
...........*......*.....*..*......*.*.........*........................*........................*..........*..................................*.................................*.....*......*...........
|
||||
.......*.................*.......................*.*.*.*.........*.............................*..........*...............................*.....................................................*........
|
||||
..*...*....*.....*.....*.*.............*................*....................................................*.....................*..............................*.......*.*....*..*..*.....**....*.....
|
||||
......................................*............*.....................................*....*................................................*.............*......*...*................................
|
||||
..........*.*...*..*...*....*...........................**................*................*.................................*....*............*...........*......*..............*......*....**.........*
|
||||
...............*.........*....*....*...........................................................................................................*..........*..............*.*.............*...*...........
|
||||
...*.....*......*.....*.......................*...........*..............*....***....................*.........*...........................*...................................*..*.....*......*.........
|
||||
............*..*........................*........*...................................*......................*..............*........*...................................................*................
|
||||
......*..*...*.*..*..*..........................*........................*...............*............*.*....*...**...........................................*....................*.....*.....*.........
|
||||
...*......*.......................................**........................*...................................*..................*..*.......*............*............*...*............................
|
||||
........*.*...*......*...*...........*.....................*.......*..........**...................*........*..................*......*..................*....*....................*......*.....*........
|
||||
.....................*..*...........................................................*...............*.................*..*......................*....*...................................................
|
||||
........*.....*...*.*.......................................**...............*.......................................................................................*..............*.....*.....*........
|
||||
........*.............................................*........*...........*........................................................................*...............................*....................
|
||||
.......*.....*.....*.............*...........*...............*..................*.............................................................*.................*....................*.....*.....*......*
|
||||
.......*.......*....*..............................*.................*.....*..........*............*..........*.........................*............*..................................*................
|
||||
.......*.....*.....*...................*.............................*....*......*..........*................................*........*..............................................*.....*.....*.....*.
|
||||
.......................................*....*..*...........*....................................*...............................*...*....*.........*..........................*........................*.
|
||||
......*.....*......*.............................*.......................*........*.*.**.........*...................*...................*....*...*....*..............*..............*......*.....*.....*
|
||||
........*...........*.........**................................*..*.....*.....................*.................*..............................*........*....*................*.*.......................
|
||||
......*...*.*.....*...........................................*.....*..*...........................................*..*..............................................*...........*....*.....*.....*......
|
||||
......................*......................................................................................**.........................*..*..*......................*..*.....**.........................
|
||||
......*.....*.....*..........*........*........................................................*...................*...............*....................*..*..........................*.....*.....*......
|
||||
........................*..................................*...*.......*..............................................................................................*.........*..*..............*......
|
||||
......*.*...*...*.*............................*..........*...........................*....*....................................*..............................**..*...*..............*....**.....*......
|
||||
...........*..............*..................................**....................................*.*.*.*.*.*.*.*.*..................................................*.............*....................
|
||||
.....**....*.....*.................................................*......*............*.......*.*.*.*.*.*.*.*.*.*.*.*..............................*...................*.....*..*.....*.....*.....*.....
|
||||
.........................................................*................*....*.............*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.............................*.....*....*......*...............................
|
||||
*.*.**.....*.....*............*...............................*.*..........*....*...........*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*............................................................*.....*.*...*.....
|
||||
........*.........................*.......*..............*.......*.........................*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*...**...............................*...........*.................*..........
|
||||
.....*...*.*.....*........................................*.....................................*.*.*.*.*.*.*.*..**...*.*.*.*........*........................*.............*..........**...**.....*.....
|
||||
..........*...........*..............................*...........*...........*.*.*.*.*...........*.*.*.*.*.*.*....*....*.*.*.*......................*...............*....................................
|
||||
.....*.....*.....*......................*................................*....*.*.*.*.*.*.*.*.....*.*.*.*.*.*...........*.*.*.*....................................*....*..............*.....*.....**....
|
||||
.....................................*..........................*...*............*.*.*.*.*.*.*.....*.*.*.*.*.*.........*.*.*.*.......*........................................................*........*.
|
||||
.....*.....*.................*....................................*.....................*.*.*.*.*...*.*.*.*.*.*.*...*.*.*.*.*.*.......*.............*.....*..................................*.....*...*.
|
||||
....................................................*...........*.....*...*........................*.*.*.*.*.*.*.*.*.*.*.*.*.*............*..........**..................................................
|
||||
.....*....**.....*.......................................*.........................*.*.*.*.*.*......*.*.*.*.*.*.*.*.*.*.*.*.*.*....*.........*.........................................*.....*.*...*.....
|
||||
.**..........*..........*....*...........................*............................*.*.*.*.*......*.*.*.*.*.*.*.*.*.*.*.*.*.......*.............*.................*...*................*.*......*.....
|
||||
.*...*.....*.....*....................................................................................*.*.*.*.*.*.*.*.*.*.*.*.*.....................*..................................**....*.....*.....
|
||||
.......................................*...*........................*...........*......................*.*.*.*.*.*.*.*.*.*.*.*.......*......*............................................*...............
|
||||
.....*.....**....*.*....................*....*.....*..*............................*......................*.*.*.*.*.*.*.*.*.*........................................................*.*.....*.....**....
|
||||
*............*.....................................................*.....*................*.......*..........*.*.*.*.*.*.*.*.................................*........*.........*.........*..............
|
||||
.....*.....*.....*..................................................*.....................*.*...*.................*.*.*.*.*............................................................*..*..*.....*.....
|
||||
.......*...........**.....................*.......*...............*...........**........................*...............*...........*.................................................**.............*...
|
||||
......*.....*.....*..........*..............*.........*....*...................................*........**.**................................................*..*.....................*.....*.....*...*..
|
||||
......*...........*..................*............*..........................*......*.................................................*........................*.........*......................*........
|
||||
......*.....*.....*.......*......................*.......*.*..*.......*..........................*........*........*.....................*............................................*.....*.....*......
|
||||
..........**.............*.............................................................*...........*..........*.............................*...........*...................................*............
|
||||
......*.....*.....*................................*...........*............*................................*.....*.................*...........................................*.*..*.....*.....**.....
|
||||
....................*...................*.................................*............*..................................................*............*...........*......................*.......*......
|
||||
......*..*.**......*........*.................................................................*.................**...........*..*............*..................................*....*..*...*.....*......
|
||||
....*.......................**..................................*..*.................*..........................................*.........*.*....*.......................................................
|
||||
.......*.....*...*.*...............................................................................*......*......................................*......*..*.......................*.*.....*.....*.......
|
||||
...**.....................................................................................*.................*........*....*...................................................*..........................
|
||||
.......*.....*.....*..................................*...................................*...........*..........................................*.................................*.*.....**....*.......
|
||||
.......................*......**...*...................*...........................................................*.......*...........*..........................*......................................
|
||||
........*....**.....*..................*.............................*....................*...........*....*.................................*...........................*..........*....**.....*..*.....
|
||||
........................................*........................*...............................*......................*.*.........*..*..............*..........*..*....................................
|
||||
........*.....*......*..........................................................................*..........*............................................*....*.............*.......*.*...**.*...*........
|
||||
.*........*..................*....................................*.............*.................................*.....................*..........................................*.......*.............
|
||||
.........*.....*.....*...................*.....*........*..*.*...................................*.........*.........................*...........................*.................*.....*.....*......*..
|
||||
..*......................*.............................................................................*..............*...........*.....*..................................*...............*.............
|
||||
.........*......*.....*...........*.........................*........*...*.......*...................*..................*................*.........*............................*.*.....*......*.........
|
||||
.......*........*..............................*.................................**.............**......*.............................*........................................*.........................
|
||||
.........**.*...*......**.............*....................................*..........................*..........*.*.....*.......................................................*.....**.....*..........
|
||||
.................................*.....*............*...*.....................................*......*........................*......*................*....................*.............................
|
||||
...........*.....*.....*..........*...........................................*....*......*..*..................*...*.....................*......................................*.*...*.....*...........
|
||||
*......................................*.......*.........*......*......................*..................*.....................*.......*.................*..............................................
|
||||
..*........*......*.....*...............*..*....................*................*.*....................................*.........................*........................*...**.*...*......*..*........
|
||||
.*..............................................*.......*..................*..................................*......................................................*........*.......*.*.....*...*......
|
||||
............*......*.....**..*.................*.*....*..........................................*.......*...................**........................*..............*.....*..*.....*...*..*............
|
||||
...............*.......*..........*.............................*....................*....**.*....*.........................................*............................................................
|
||||
....*....*...*......*.....*...........*......................................................................................*..................................*.............*.....*......*.*...........
|
||||
...............................*................................*.........................*..............*................*..............*..............*......................*............*.....**.....
|
||||
............*.*.....*......*..........................................*.......*...........**.....*.............................*...................*........................**......*.....*............*.
|
||||
........*.....................................*........................................*...............................*.............*..................*.*.............*..............*.*............*..
|
||||
...............*......*...*.*..............*.*...........**...................................................*........................*.*.......*..........................*.....**.....*..*............
|
||||
..................*......*..................*.......*........*...*....*.*...............................*........*....................................................................................*.*
|
||||
*...............*......*......*..................*..*.*.......................................................................*.......................................*...**.....*......*................
|
||||
..................................*...*.............................................................................*.*.................*...............*....................................*......*....
|
||||
..............*..*......*.**...*...*...........*............*..............*.......................................................*....................................**......*......*.................
|
||||
.................................**............................*...**......*.............*.................*..............*.........................................*....................................
|
||||
..................*......*....*.*.........*.*............................**.....*..*........................*.....**.......*...*............*................*......*...*......*......*..................
|
||||
..*...............................................................*.*....**..............................................................*.....*.........................................*...............
|
||||
................*..*......**......*...............................*....................*..........*...................*.*.................*..*...............*........*.......*..*...*...................
|
||||
............*.......*...*.........................................................*..............................................................*..........................................*...*........
|
||||
....................*.......*......*..*....................................*...................................................................................**....*......*.......*....................
|
||||
............................................................................*...................................*.................................*.........*.*........................*..........*......
|
||||
......................*......*.......*......................*......*.*..................*......*............................**.........................*.........*.*.......*......*......................
|
||||
........*..................................................*..................*.........................*.........................*......*..................*................*...........................
|
||||
.*.....................**....*.*.......*.................*.*.......**......................*.........................**...........*..*.................*.........*.......*.......*...........*....*......
|
||||
......*..........*.......................*................................................................*..*.................................................*.......................*...*.......*.....
|
||||
.........................*..*...*........*..............................*.........*..........................*.......*......*..........................*......**........*......*..*......*..........*....
|
||||
..*........................*..........*......................................................*........*....*.....*...................*.....................................*.......*..........*..........
|
||||
..........*..............**.......*.......**.........................*...*............*........*.*............................*..*...*.......................*........*..*...**.....................*....
|
||||
...............*.........*..........*............*................................................................*.............................*.....*.......*.............................**...........
|
||||
.*..........................*..*....*........*..............*........*.*..................................................................................**........*.......*........................*...
|
||||
.........................................................*...............*...........*...........................*..**........*..........*......*........................................................
|
||||
........*.*...................*.......*........*............*.....*..**..............................**............*....................*.............*..*........*.......*.............*................
|
||||
...............................*.........*............*............*..*..............*.................*....*............*........*.....*.................*............*....*............................
|
||||
.................................*.......*.......................................................................*......................................................................*...............*
|
||||
.*..........*.................*...........................................*.......................*......*................................*...........**...............*......*................*.........
|
||||
......................*................................................*......*.......*.....*.*......*.....................*.*................*.*.........................*.....*.............*..**.....*
|
||||
....*.*......................*..*....*..........*.....................*.......**..............................................*.......*....................................**...*......*.........*.......
|
||||
.........*...................*................*............*...*.................*.........****.............................*........................................................*...................
|
||||
...............*.............**.................*.........*.....*........................................*......................*..........................................*..............*..............
|
||||
.............*...........................*................................................................................................................*..............................................
|
||||
.....*............*....................................................*..........*..*......*.........................................................................*.....................*.*..........
|
||||
....*.........................................*..............*.............*.........................................*.......*..*...................*...................................*..............**
|
||||
*..................*.................................*................*.................................**...*............*.............*...*.........*......*...........................*.............**
|
5
2024/day17_galactic_geometry/tests/sample1
Normal file
5
2024/day17_galactic_geometry/tests/sample1
Normal file
|
@ -0,0 +1,5 @@
|
|||
*...*
|
||||
..*..
|
||||
.....
|
||||
.....
|
||||
*.*..
|
5
2024/day17_galactic_geometry/tests/sample2
Normal file
5
2024/day17_galactic_geometry/tests/sample2
Normal file
|
@ -0,0 +1,5 @@
|
|||
*...*
|
||||
..*..
|
||||
.....
|
||||
.....
|
||||
*.*..
|
7
2024/day17_galactic_geometry/tests/sample3
Normal file
7
2024/day17_galactic_geometry/tests/sample3
Normal file
|
@ -0,0 +1,7 @@
|
|||
.......................................
|
||||
..*.......*...*.....*...*......**.**...
|
||||
....*.................*.......*..*..*..
|
||||
..*.........*.......*...*.....*.....*..
|
||||
......................*........*...*...
|
||||
..*.*.....*...*.....*...*........*.....
|
||||
.......................................
|
6
2024/day18_the_ring/Cargo.toml
Normal file
6
2024/day18_the_ring/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "day18_the_ring"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
235
2024/day18_the_ring/challenge.txt
Normal file
235
2024/day18_the_ring/challenge.txt
Normal file
|
@ -0,0 +1,235 @@
|
|||
Part I
|
||||
|
||||
Near the rapidly constructed shrine of the god Nullpointer, a new area is being allocated for palm tree cultivation. The terrain of the desert is quite suitable for these plants but also challenging, requiring a well-planned irrigation system to ensure efficient growth.
|
||||
The irrigation system is a network of channels that will continuously supplies water to the trees. However, there are concerns about the distance over which an adequate amount of water can be delivered. The sun may evaporate the stream so quickly that the water disappears before reaching all the targets.
|
||||
The first palm farm is already under construction, but the knights are still analysing its design (your notes). The palm trees are marked with P , and the channels are marked with . . The remaining areas, marked as # , are designated paths for workers, and must remain at ground level.
|
||||
The edge of the farm has exactly one cell marked as part of the channel: . . This is where the water will enter the farm. Every minute the water spreads to all adjacent channel segments vertically and horizontally. The segments with palm trees are at the same level as the channel, and water can flow through them just like a regular channel segment.
|
||||
The task for the tournament challengers is to calculate the time needed for the water to reach all the palm trees from the moment the channel is supplied with water at the edge point.
|
||||
Example based on the following notes:
|
||||
##########
|
||||
..#......#
|
||||
#.P.####P#
|
||||
#.#...P#.#
|
||||
##########
|
||||
The water flow ( ~ ) starts from the left side and goes as follows:
|
||||
##########
|
||||
~.#......#
|
||||
#.P.####P#
|
||||
#.#...P#.#
|
||||
##########
|
||||
time: 0
|
||||
##########
|
||||
~~#......#
|
||||
#.P.####P#
|
||||
#.#...P#.#
|
||||
##########
|
||||
time: 1
|
||||
##########
|
||||
~~#......#
|
||||
#~P.####P#
|
||||
#.#...P#.#
|
||||
##########
|
||||
time: 2
|
||||
##########
|
||||
~~#......#
|
||||
#~P.####P#
|
||||
#~#...P#.#
|
||||
##########
|
||||
time: 3
|
||||
##########
|
||||
~~#......#
|
||||
#~P~####P#
|
||||
#~#...P#.#
|
||||
##########
|
||||
time: 4
|
||||
##########
|
||||
~~#~.....#
|
||||
#~P~####P#
|
||||
#~#~..P#.#
|
||||
##########
|
||||
time: 5
|
||||
##########
|
||||
~~#~~....#
|
||||
#~P~####P#
|
||||
#~#~~.P#.#
|
||||
##########
|
||||
time: 6
|
||||
|
||||
|
||||
##########
|
||||
~~#~~~...#
|
||||
#~P~####P#
|
||||
#~#~~~P#.#
|
||||
##########
|
||||
time: 7
|
||||
##########
|
||||
~~#~~~~..#
|
||||
#~P~####P#
|
||||
#~#~~~P#.#
|
||||
##########
|
||||
time: 8
|
||||
##########
|
||||
~~#~~~~~.#
|
||||
#~P~####P#
|
||||
#~#~~~P#.#
|
||||
##########
|
||||
time: 9
|
||||
##########
|
||||
~~#~~~~~~#
|
||||
#~P~####P#
|
||||
#~#~~~P#.#
|
||||
##########
|
||||
time: 10
|
||||
##########
|
||||
~~#~~~~~~#
|
||||
#~P~####P#
|
||||
#~#~~~P#.#
|
||||
##########
|
||||
time: 11
|
||||
All the palm trees receive water after 11 minutes.
|
||||
How much time is needed for the water to reach all the palm trees on the first farm?
|
||||
|
||||
Part II
|
||||
|
||||
The second farm will be much larger, but water will be supplied simultaneously from two points on opposite sides, so everything should be irrigated in reasonable time.
|
||||
Example based on the following notes:
|
||||
#######################
|
||||
...P..P...#P....#.....#
|
||||
#.#######.#.#.#.#####.#
|
||||
#.....#...#P#.#..P....#
|
||||
#.#####.#####.#########
|
||||
#...P....P.P.P.....P#.#
|
||||
#.#######.#####.#.#.#.#
|
||||
#...#.....#P...P#.#....
|
||||
#######################
|
||||
The water flow ( ~ ) starts simultaneously from the left and right sides and proceeds as follows:
|
||||
#######################
|
||||
~..P..P...#P....#.....#
|
||||
#.#######.#.#.#.#####.#
|
||||
#.....#...#P#.#..P....#
|
||||
#.#####.#####.#########
|
||||
#...P....P.P.P.....P#.#
|
||||
#.#######.#####.#.#.#.#
|
||||
#...#.....#P...P#.#...~
|
||||
#######################
|
||||
time: 0
|
||||
#######################
|
||||
~~.P..P...#P....#.....#
|
||||
#.#######.#.#.#.#####.#
|
||||
#.....#...#P#.#..P....#
|
||||
#.#####.#####.#########
|
||||
#...P....P.P.P.....P#.#
|
||||
#.#######.#####.#.#.#.#
|
||||
#...#.....#P...P#.#..~~
|
||||
#######################
|
||||
time: 1
|
||||
#######################
|
||||
~~~P..P...#P....#.....#
|
||||
#~#######.#.#.#.#####.#
|
||||
#.....#...#P#.#..P....#
|
||||
#.#####.#####.#########
|
||||
#...P....P.P.P.....P#.#
|
||||
#.#######.#####.#.#.#~#
|
||||
#...#.....#P...P#.#.~~~
|
||||
#######################
|
||||
time: 2
|
||||
|
||||
|
||||
#######################
|
||||
~~~P..P...#P....#.....#
|
||||
#~#######.#.#.#.#####.#
|
||||
#~....#...#P#.#..P....#
|
||||
#.#####.#####.#########
|
||||
#...P....P.P.P.....P#~#
|
||||
#.#######.#####.#.#.#~#
|
||||
#...#.....#P...P#.#~~~~
|
||||
#######################
|
||||
time: 3
|
||||
#######################
|
||||
~~~P~.P...#P....#.....#
|
||||
#~#######.#.#.#.#####.#
|
||||
#~~...#...#P#.#..P....#
|
||||
#~#####.#####.#########
|
||||
#...P....P.P.P.....P#~#
|
||||
#.#######.#####.#.#~#~#
|
||||
#...#.....#P...P#.#~~~~
|
||||
#######################
|
||||
time: 4
|
||||
... #######################
|
||||
~~~P~~P~~~#P~~~~#.....#
|
||||
#~#######~#~#~#~#####.#
|
||||
#~~~~~#~~~#P#~#~~P....#
|
||||
#~#####~#####~#########
|
||||
#~~~P~~~~P~P~P~~~~~P#~#
|
||||
#~#######~#####~#~#~#~#
|
||||
#~~~#~~~~~#P~~~P#~#~~~~
|
||||
#######################
|
||||
time: 21
|
||||
|
||||
All the palm trees receive water after 21 minutes.
|
||||
How much time is needed for the water to reach all the palm trees on the second farm?
|
||||
|
||||
Part III
|
||||
|
||||
The last of the farms is the largest, but it doesn't have any entry points for water sources at the edge. It turns out that there are groundwater reserves beneath the land and they are under high pressure, so it's enough to dig a big well (that occupies the entire segment) in the optimal spot and let nature take care of the rest.
|
||||
It has been found that water evaporates significantly when flowing through the channels, so the well should be dug at one of the channel segments marked with . where the sum of the times it takes for the water to reach all the palm trees is minimised.
|
||||
Example based on the following notes:
|
||||
##########
|
||||
#.#......#
|
||||
#.P.####P#
|
||||
#.#...P#.#
|
||||
##########
|
||||
One of the possible locations for the well is on the right side of one of the palm trees. The water flow ( ~ ) for that spot looks as follows:
|
||||
##########
|
||||
#.#......#
|
||||
#.P~####P#
|
||||
#.#...P#.#
|
||||
##########
|
||||
time: 0
|
||||
##########
|
||||
#.#~.....#
|
||||
#.P~####P#
|
||||
#.#~..P#.#
|
||||
##########
|
||||
time: 1
|
||||
##########
|
||||
#.#~~....#
|
||||
#~P~####P#
|
||||
#.#~~.P#.#
|
||||
##########
|
||||
time: 2
|
||||
##########
|
||||
#~#~~~...#
|
||||
#~P~####P#
|
||||
#~#~~~P#.#
|
||||
##########
|
||||
time: 3
|
||||
##########
|
||||
#~#~~~~..#
|
||||
#~P~####P#
|
||||
#~#~~~P#.#
|
||||
##########
|
||||
time: 4
|
||||
##########
|
||||
#~#~~~~~.#
|
||||
#~P~####P#
|
||||
#~#~~~P#.#
|
||||
##########
|
||||
time: 5
|
||||
##########
|
||||
#~#~~~~~~#
|
||||
#~P~####P#
|
||||
#~#~~~P#.#
|
||||
##########
|
||||
time: 6
|
||||
|
||||
|
||||
##########
|
||||
#~#~~~~~~#
|
||||
#~P~####P#
|
||||
#~#~~~P#.#
|
||||
##########
|
||||
time: 7
|
||||
The first palm receives water after just 1 minute. The second needs to wait for 4 minutes, and the third for 7 minutes.
|
||||
Summing these times gives a total of 1 + 4 + 7 = 12 minutes. Digging the well at any other location would result in a greater sum of times, so this is the optimal point for digging.
|
||||
Dig the well at the optimal point. What is the sum of the times it takes for the water to reach all the palm trees?
|
182
2024/day18_the_ring/src/lib.rs
Normal file
182
2024/day18_the_ring/src/lib.rs
Normal file
|
@ -0,0 +1,182 @@
|
|||
use core::fmt::Display;
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ParseError {
|
||||
EmptyMap,
|
||||
InvalidChar(char),
|
||||
}
|
||||
|
||||
impl Display for ParseError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::EmptyMap => write!(f, "Input was empty"),
|
||||
Self::InvalidChar(e) => write!(f, "Unable to parse {e}. Valid characters are \'.\', \'#\', and \'P\'."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Coordinates = (usize, usize);
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Map {
|
||||
walkable: Vec<Vec<bool>>,
|
||||
trees: Vec<Coordinates>,
|
||||
entries: Vec<Coordinates>,
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for Map {
|
||||
type Error = ParseError;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
let mut walkable = Vec::new();
|
||||
let mut trees = Vec::new();
|
||||
let mut entries = Vec::new();
|
||||
|
||||
for (y, line) in value.lines().enumerate() {
|
||||
let mut walkable_line = Vec::new();
|
||||
for (x, c) in line.chars().enumerate() {
|
||||
match c {
|
||||
'.' => walkable_line.push(true),
|
||||
'#' => walkable_line.push(false),
|
||||
'P' => {
|
||||
walkable_line.push(true);
|
||||
trees.push((y, x));
|
||||
},
|
||||
e => return Err(Self::Error::InvalidChar(e)),
|
||||
}
|
||||
}
|
||||
walkable.push(walkable_line);
|
||||
}
|
||||
if walkable.is_empty() {
|
||||
return Err(Self::Error::EmptyMap);
|
||||
}
|
||||
if let Some(x) = walkable[0].iter().position(|w| *w) {
|
||||
entries.push((0, x));
|
||||
}
|
||||
if let Some(x) = walkable.last().unwrap().iter().position(|w| *w) {
|
||||
entries.push((walkable.len()-1, x));
|
||||
}
|
||||
if let Some(y) = walkable.iter().position(|row| row.first() == Some(&true)) {
|
||||
entries.push((y, 0));
|
||||
}
|
||||
if let Some(y) = walkable.iter().position(|row| row.iter().last() == Some(&true)) {
|
||||
entries.push((y, walkable[y].len()-1));
|
||||
}
|
||||
Ok(Self { walkable, trees, entries, })
|
||||
}
|
||||
}
|
||||
|
||||
impl Map {
|
||||
fn water(&self) -> Vec<usize> {
|
||||
let mut open_set = self.entries.iter().map(|e| (*e, 0)).collect::<VecDeque<_>>();
|
||||
let mut to_collect = self.trees.clone();
|
||||
let mut visited: HashSet<Coordinates> = self.entries.iter().cloned().collect();
|
||||
let mut watering_times = Vec::new();
|
||||
|
||||
while let Some(((y, x), dist)) = open_set.pop_front() {
|
||||
if let Ok(idx) = to_collect.binary_search(&(y, x)) {
|
||||
to_collect.remove(idx);
|
||||
watering_times.push(dist);
|
||||
}
|
||||
if to_collect.is_empty() {
|
||||
return watering_times;
|
||||
}
|
||||
[(1,0), (1,2), (0,1), (2,1)]
|
||||
.iter()
|
||||
.filter(|(dy, dx)|
|
||||
y + dy > 0 &&
|
||||
y + dy <= self.walkable.len() &&
|
||||
x + dx > 0 &&
|
||||
x + dx <= self.walkable[y + dy - 1].len() &&
|
||||
self.walkable[y + dy - 1][x + dx - 1]
|
||||
).for_each(|(dy, dx)| {
|
||||
let new_pos = (y + dy - 1, x + dx - 1);
|
||||
if !visited.contains(&new_pos) {
|
||||
visited.insert(new_pos);
|
||||
open_set.push_back((new_pos, dist+1));
|
||||
}
|
||||
});
|
||||
}
|
||||
// We didn't find a path to all the plants
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn best_watering(&mut self) -> Option<usize> {
|
||||
// Find the best spot by watering from the trees and noting how much combined time was
|
||||
// spent to reach it. Note that this isn't necessarily the spot we reach first.
|
||||
let mut open_set = self.trees.iter().enumerate().map(|(idx, t)| (*t, idx, 0)).collect::<VecDeque<_>>();
|
||||
let mut visited: HashMap<Coordinates, (Vec<usize>, usize)> = self.trees.iter().enumerate().map(|(idx, t)| (*t, (Vec::from([idx]), 0))).collect();
|
||||
|
||||
while let Some(((y, x), orig, dist)) = open_set.pop_front() {
|
||||
[(1,0), (1,2), (0,1), (2,1)]
|
||||
.iter()
|
||||
.filter(|(dy, dx)|
|
||||
y + dy > 0 &&
|
||||
y + dy <= self.walkable.len() &&
|
||||
x + dx > 0 &&
|
||||
x + dx <= self.walkable[y + dy - 1].len() &&
|
||||
self.walkable[y + dy - 1][x + dx - 1]
|
||||
).for_each(|(dy, dx)| {
|
||||
let new_pos = (y + dy - 1, x + dx - 1);
|
||||
if !visited.contains_key(&new_pos) || !visited.get(&new_pos).unwrap().0.contains(&orig) {
|
||||
visited.entry(new_pos).and_modify(|(trees, d)| {
|
||||
trees.push(orig);
|
||||
*d += dist;
|
||||
}).or_insert((vec![orig], dist));
|
||||
open_set.push_back((new_pos, orig, dist+1));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Now, exccluding spots with a tree in them, find the one with the best score.
|
||||
if let Some(entry) = visited
|
||||
.iter()
|
||||
.filter(|(coords, _)| !self.trees.contains(coords))
|
||||
.min_by_key(|(_coords, (_trees, dist))| dist)
|
||||
.map(|(coords, _)| coords)
|
||||
{
|
||||
self.entries.push(*entry);
|
||||
Some(self.water().iter().sum())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(input: &str, part: usize) -> Result<usize, ParseError> {
|
||||
let mut map = Map::try_from(input)?;
|
||||
match part {
|
||||
1 | 2 => Ok(*map.water().last().unwrap()),
|
||||
3 => Ok(map.best_watering().unwrap()),
|
||||
_ => panic!("Illegal part number"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs::read_to_string;
|
||||
|
||||
fn read_file(name: &str) -> String {
|
||||
read_to_string(name).expect(&format!("Unable to read file: {name}")[..]).trim().to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sample() {
|
||||
let expected = [11, 21, 12];
|
||||
for part in 1..=expected.len() {
|
||||
let sample_input = read_file(&format!("tests/sample{part}"));
|
||||
assert_eq!(run(&sample_input, part), Ok(expected[part-1]));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_challenge() {
|
||||
let expected = [103, 1383, 246261];
|
||||
for part in 1..=expected.len() {
|
||||
let challenge_input = read_file(&format!("tests/challenge{part}"));
|
||||
assert_eq!(run(&challenge_input, part), Ok(expected[part-1]));
|
||||
}
|
||||
}
|
||||
}
|
11
2024/day18_the_ring/tests/challenge1
Normal file
11
2024/day18_the_ring/tests/challenge1
Normal file
|
@ -0,0 +1,11 @@
|
|||
###############################
|
||||
...P#.....#...#P.....P#.....#P#
|
||||
#.###.###.#.#.#####.###.#.#.#.#
|
||||
#.#...#P#...#.#...#.....#.#...#
|
||||
#.#.###.#####.#.#.#.#####.###.#
|
||||
#...#.........#.#.#..P#...#P#.#
|
||||
#####.#########.#.#####.###.#.#
|
||||
#..P#.#.........#...#...#...#.#
|
||||
#.###.#.###########.#.###.#.#.#
|
||||
#.......#P............#P..#...#
|
||||
###############################
|
71
2024/day18_the_ring/tests/challenge2
Normal file
71
2024/day18_the_ring/tests/challenge2
Normal file
|
@ -0,0 +1,71 @@
|
|||
#########################################################################################################################################################################################################
|
||||
...P#..P...P#..P...P..#P......#P...P#...#.#.....PPP...#...#.P.....#.....#.....#P#.....#P.P...P..#...#.....#..P...P.P..#...#.....P..P......#P....P.PPP...#............P..#P......#.........#.....PP.P#...#
|
||||
#.#.#.#####.#.###.###.#.#####.###.#.#.#.#.#.#########.#.#.#.#.###.#.###.#.###.#P#.###.#.###.###.#.#.###.#.#.#########.#.#.#.###########.#.###.#########.#.#.###########.#####.#.###.#.###.###.#####.#.###
|
||||
#P#.#.#..P#.#..P#.#.#...#PP....P.P#...#.#.#P#.......#...#...#.#.....#P..#.#P..#.#...#P#.#P#.#.#P..#...#.#..P#.......#...#.#....P#..P..#.#P....#.......#.#.#.....#.....#P..#P..#..P#.#.#P#.#..P#.....#...#
|
||||
#.#.#.#.#.#.#####.#.#.#################.#.#.#.#####.#########P#########.#.###.#.###.#.#.#.#.#.#######.#.#####.#.#########.#####.#.#####.#######.###.###.#.#####.#.###.###.#.#####P###.#.#.#.###.#####.#.#
|
||||
#.#.#..P#P#P.P....#...#.....#..P..#P#....P#...#P..#.....#..P#.#...P...#P#...#....P#P#.#...#.#..P..#...#.....#.#........P#....P#...#.....#...#..P#P#....P#P....#P....#.#.#..P#...#.....#...#...#.#P.P#.#.#
|
||||
#.#.#####.#############.###.#.###.#.#.###########.#####.###.#.#.#####.#.###.#######.#.#.###.#.###.#.#######.#.#####.#########.#####.#####.#.#.###.###############.###.#.#####.#.#######.###.#.#.#.#.#.#P#
|
||||
#.#P#.....#..P.P...P.P#.#P#...#.#P#...#...........#P..#P.P..#...#...#.#...#...#P....#.#.#...#.#P..#P....P...#P#..P..#...P..P..#..P..#.....#.#.#.#....P..#..PP...#P#...#.......#P#...P...#P..#.#..P#.#.#.#
|
||||
#P#.#.###.#.#########.#.#.#####.#.#.###.#######.###.#.#####.#####.#.#.###.###.#.#####.#.#.###.###.#############.#####.#########.#####.#####.#.#.#.#.###.#.#####.###.###.#########.###########.#####P#.#P#
|
||||
#.#.#...#.#.#P....#P#P#.#.......#.#.#...#P...P#.....#...#...#.....#.#.#P#...#......P#..P#...#P..#....PPP.....PPP#...#P#.PP.....P#...#.....#...#...#.#P#P..#..P#...#P#......P....#.#...#P......#..P#.#.#.#
|
||||
#.#.###.###.###.#.#.#P#P#######.#.###.###.###.#########.#.###.###.###.#.###.#######.#######.###.###########.#####.#.#.#.#####.#####.#####.#####.###.#.#######.###.#P#.#######.#.#.#.#.#.#######.#.#P#.#.#
|
||||
#P#...#.#.PP#...#.#.#P#.#P......#.#P..#...#..P#.....#...#...#..P#.#..P#...#.......#P......#...#.......#..P#.#P.P.P#P..#P#...#.#.....#...#P#P....#...#......P#.#...#.#...#...#P#.#P#.#..P#P....#.#P#.#P#.#
|
||||
#.###.#.#.###.###.#.#.#.#.#####.#.#.#####.#.###.#.#.#.#.###.###.###.#####.#######.###########.#.#####.#.###.#.#########.#P#.#.#.###.#.###.###.###.#####.###P#.#.###.#####.#.###.#.#.#######.#.#.###.###.#
|
||||
#...#P#...#...#.#.#P#.#P..#..P#P#...#...#.#..P..#P#P#P#...#.#...#P..#P........#P#...#..P#.....#..P.P#.#.#P.P#...#....P#.#.#...#...#.#...#P..#...#P....#.#P#...#P...P#..P#.#..P#.#...#.......#...#...#...#
|
||||
#.#.#.###P#.###.#.#P#.#####.#.#.#####.#.###.#####P#.#P#####.#.#.#.#####.#####.#.###.#.#.#.#####.#####.#.#.#####.#.###.###.#######.#.###.###.#.#######.#.#.###.#######.#.#.###.#.#####.###########.###.###
|
||||
#P#.#...#..P#P....#.#P#.....#.#.#.#P..#P.P#..P.P#P#.#.#....P#.#.#.#...#...#......P#..P#P..#..P#.#....P#.#.#.....#..P#P....#P...P..#.....#P..#P#...#...#.#...#P#P......#.#P#.........#..P..P..P#...#P....#
|
||||
###.###.#####.#####.#.#.#.#####.#.#.#.###.#####.#.###.#.#####.#.#.#.#.###.#.###############.###.#.#####.#.#.#####.#.#########.#########.#.#####.#.#.###.###.#.#.#######.#.#.#########.#######.#.#####.#.#
|
||||
#...#...#...#...#...#.#.#....P..#...#...#..P#P..#.#...#...#...#.#.#.#.....#...#P..#...P...#.....#P#...#P..#...#P..#...#.......#P......#.#...PP..#.#..P#.#...#P#..P.P.P#P..#...#......P#P....#...#...#P#.#
|
||||
#.#.#.###.#.###.#.###.#.#########.#####.###.#####.#.#.###.#.#.###.#.#######.###.#.#.#####.#.#####.#.#.###.###.#####.#.#####.#####.#####.#########.###.#P#.###.#.#####.#######.#.#########.#.#####.#.###.#
|
||||
#.#.#P...P#.#P..#.#P..#.....#PPP...P..#.#..P#.....#.#..P#.#.#P#...#...P...#.#..P#....P#P..#...#P#.#.#...#.#...#..P#P#.#...#.....#...#...#P..#...#.#...#.#.....#.....#.#P..#P..#.#........P#..P.P..#...#.#
|
||||
#.#########.###.#.#.#.#####.#########.#.#.###.###.#.#####.#.###.###.#####.#.#.#########.#.###.#.#.#.###.###.###.#.###.#.#.###.#.###.#.###.#.#.#.#.#.###.###.###.#####.#.#.#.###P#.#####.#############.#.#
|
||||
#.........#...#...#P#.#..P#..P..#P#...#P#..P..#P..#..P....#.#P..#P....#P..#P#.#.....P...#P..#.#.#P#P#.#P#...#...#.....#.#...#P#...#...#...#P..#P#P..#.....#.#P..#P....#.#...#P#.#.#.....#..PP.PP..#...#.#
|
||||
#.#####.#.###.###.#.#.#.#######.#.#.###.#######.###########.#.#########.###.#.#.###########.#.#.#.#.#P#.#.###.#####.###.###.#.###.#####.#######.#####.###.#.#####.#####.#####.#.#P#.#####.#######.###.#.#
|
||||
#..P#..P#..P#P#...#.#.#.......#.#P#..P#.....#.#P........#P..#.........#..P#P#P#.......#.....#.#P#..P#.#...#P..#....P#...#...#.#.#..P#..P#.....#....P#.#.#.#.....#.#..P#.#...#.#.#P#.....#..P.P..#..P#...#
|
||||
#.###.#####.#.#####.#.###.###.#.#.###.#####.#.#########.#.#.#########.#.#.###.#######.###.###.#.#####.#####.#####.###.###.###.#P###.#.#####.#.#.#####.#.#.#####.#.#.###.#.#.#P#.#######.#######.###.###.#
|
||||
#.#..P#P....#P.P#P..#.....#P.P#.#.........#.#P...P#...#.#P#...#.....#P#.#...#.#....P#P..#.#...#.......#.....#P..#.#...#.#P#.#P#.#P..#..P#...#P#P#....P#.#.....#...#...#..P#.#P#P......#...PP..#.#P.P#P#.#
|
||||
#.#.#######.###.#.#######.#####.#.#######.#.#####.#.#.#.#####.#.#.###.#.###.#.#.###.###.#P#.#####.#.#.#.###.#.#.#.#.###.#.#.#.#.#.#####.#.###.#.#.#####.#####.#######.#####.#.#######.#######.#.#.###.#.#
|
||||
#P#P.....P#.#...#P#PPPP..P#P...P#P#..P#...#.....#...#.#....P#..P#...#.#...#...#.#.#.#...#P#.#...#.#.#...#...#.#.#.#.#P..#.#P...P#.#...#P..#.#.#P..#.....#...#..P#P.....P..#....P.P#P#P.PP..P#P..#P..#P#.#
|
||||
#P#######.###.###.#########.#######.#.###.#####.#####.#####.#######.#.###.#####.#.#.#.#####.#.#.#.#P###.#####.#.###.###.#.#######.#.#.#####.#.#########.#.#.###.###.#####.#######.#.#######.#######.#.#.#
|
||||
#.#P..#...#...#.....#..P.P..........#..P#.....#...#.......#P....P..P#...#...P...#...#P....#.#.#.#.#.#...#P....#...#P....#.......#...#.#..P.....P......#...#..P#...#.#PPP..#P.P.......P#.....#....P..#...#
|
||||
###.#.#.#.#.#####.#.#.#################.#########.#.#########.#########.#######.#########.#.#.#.###P#####.#######.#####.#######.#####.#.#############.#.###.#####.#.#######.###########.#####.#######.###
|
||||
#...#...#.#P#P.P#.#P#...#...PP..#P.P..#.....#...#P#...#.....#.#P........#..PP.P.#P........#P..#...#P#..P........#P.P..#...#P..#.....#...#..P#P.P..#P..#..P#...#P..#P#...#...#....P..#...#...#.#.....#..P#
|
||||
#.#######.#.#.#.#.#.#.###.#####.#####.#####.#.#.#.#.#.#.###.#.#.#########.#######.#######.#######.#P#.###############.###.#.#.#####.###.#.#.#.###.###.#######.#.###.#.#.#.###.#####.#.###.#.#P#.###.#####
|
||||
#...#.....#...#.#P#..P#...#P#...#...#..P..#...#..P#P#...#.#..P#P........#P#..P#...#.#........P.P#.#.#...#..P#.......#...#.#.#....P#...#...#.#...#...#........P#.#.....#.#..P#..P#...#.#...#P#.#..P#P.P..#
|
||||
#.#.###.#######.#P#####.###.#.###.#.#####.#########.#####.#########.###.#P###.#.###.#.###########.#P###.#.#.#.#####.#.#.#.###.#.#####.#####.###.###.###.#######.#.#####.#.#####.#.#.#.#.###.#.###.#####.#
|
||||
#P#...#...#..P#.#P#P.P#P#P#...#...#.#P.P#P#..P....#.#P......#..P.P#.#.#.#.#P..#.#P....#...#P..#...#.#...#.#...#...#...#.#.#...#P#P.P#.....#.#P..#P#..P#.#P.PPP..#P#P#...#.#..P#P#.#P#.#..P#.#......PP.#.#
|
||||
#.###.###.#.###.#.#.#.#.#.#.###.#.#.#.#.#.#.#####.#.#######.#.###.#.#.#.#.#.#.#.###.#####.#.#.#.###.#.###.#####.###.#####.#.#.###.#.#.###.#P#.###.###.#.#.#######.#.#.###.#.#.#.#.###.#.#.#P###########.#
|
||||
#.#.#...#P#...#.#...#.#.#.#.#P.P#.#...#.#P..#P....#.#..P#P..#P.P#P#...#.#..P#.#..P#.......#P#.#.#...#.#...#.....#...#.....#.#.#P.P#.#...#.#.#.#......P#.#.#P....#...#...#P#.#...#P....#.#.#.......#P....#
|
||||
#.#.###.#.###.#.###.###.#.#.#####.#####.#####.#.###.#.#.#.#.###.#.#####.#####.###.#######.#.#.#.#.###.#.#######.#.###.#####.###.###.#####.###P#.#######P#.###.#####.###.#P#.#############.#######.#.###.#
|
||||
#.....#.#...#.#P#...#...#.#...#...#...#.....#.#P#.....#...#..P#.#....P#....P#...#...#P..#P#.#..P#...#.#...#P..#....P#...#P..#...#...#P..#..P#P#...#..P#P#...#.........#.#.#.#P.......P#...#...#P#..P#..P#
|
||||
#.#####.###.#.#.#####.###.###.#.###.#.#####.#.###.#############.#####.###.#.#.#####.#.#.###.#####.#.#.###.#.#.#########.###.#.###.###.#.###.#.###.#.#.#####.#####.#####.#P#.#####.###.#.###.#.#.#####.###
|
||||
#.#.....#.....#.#..P..#.....#P#.#...#P#P....#..P#.#...P.....#...#P.P#..P#.#.#.#.....#.#.....#...#.#P#..P#P#.#.....#..P..#...#.#.#.#..P#P..#P#.#....P#.#...#..P..#.#.....#.#.#..P.P#.#P#...#P#.#.....#.#.#
|
||||
#.#.###########.#.#####.###.#.#.#.#.###.#######.#.#.#######.#.#####.###.###.#.#.#####.#######.###.#.###.#.#.#####.#.#####.#.#.#.#.#.#####.#.#.#######.#.#.#####.#P#.###.#P#.#.#####.#.#.#.#.#.###.#.#.#.#
|
||||
#.#...P.P......P#..P..#.#.#..P#P#.#P#...#P.....P#.#.......#.#.#P......#P#..P#.#....P#.......#.....#.....#.P.#.#...#...#...#.#.#..P#P..#.....#...PP..#P..#P#..P..#P#P#..P#.#...#P....#.#.#P#.#.....#.#...#
|
||||
#.###############.###.#.#.#####.#.###.#####.#####.#######.#.#.#.#.#####.#.#########.#.#####.###########.#####.#.#####.#.###.#.#.#####.#######.#####.#####.#.#######P#.###.#########.#.###.#.###.#######.#
|
||||
#..P.P#.....#..P..#.#P#...#.....#.....#P..#..........P..#.#...#.#.#.....#...#P....#...#..P#P..........#...#...#P........#...#P#.......#P..#....P..#.#P..#P#...#..P#.#P..#P.....P....#...#.#P#...#....P#.#
|
||||
#####.###.#.#.#####.#.###.#.#.###.#####.#.#############.#.#######.#.#####.#.#.###.#.###.#.###########.###.#.#.###########.###.#.#######.#.###.#####.#.#.#.###.#.#.#.###.###########.###.#.#.#.###.###.#P#
|
||||
#...#.#P..#.#.#.....#.#P#.#.#P..#.......#........P.P#P..#...#P....#PPP.P#P#P#.#.#.#P#...#.#PP...#P.P.P#.#.#.#...#....P#.#.#P..#P#P.....P#P..#.#.....#.#P#...#.#.#...#P..#P....P.....#P#.#.#P#...#P..#.#P#
|
||||
#.#.#.#.###.#.###.###.#.#P#P###.###################.#####.#.#.###.#####.###.#.#.#.###.###.#####.#.#####.#.#.###.#.###.#P#.#.#####.#########.#.#.#####.#.###.#.#.#####.###.###########.#.#.#.#######.#.#.#
|
||||
#.#P#P.P#P#P#....P#...#P#.#.#...#...#.#.....#P...P#.....#.#.#.#..P#P..#...#.#P..#..P#.#P#....P#.....#P......#...#.#.#P#.#.#..P#P..#P........#.#.#.PP..#...#P#.#...#P....#.#P...P#.....#P..#......P#P#..P#
|
||||
#.#######.#.#######.###.#.###.###.#.#.#.#.###.###.#####.#P#.#.#.#####.###.#.###.###.#.#.#####.#####.###.#######.#.#.#.#.#.###.#.###.#########.#P#####.#####.#.#.#.#####.#.###.#.#.###.#######.###.#.#####
|
||||
#....P..#.#.......#.#...#..P#..P..#.#...#.......#....P#.#P#.#P#P........#.#...#...#...#P...P#P.P..#...#...#P.P#P#P#...#....P#.#..P#.#...#.....#.#P..#P.......P#.#P....#P#.....#.#...#.......#...#.#.#...#
|
||||
#.#.###.#.#######.#P#.#.###.#.#####.#.#############.###.###.#.###########.#.#.###.#########.#####.###.#.###.#.###.#.#########.###.#.#.#.#.#####.#.#.###.#######.#####.#########P#.###.#####.#####.#.###.#
|
||||
#.#.#P#.#.....#...#.#.#..P#.#P.P#...#....P#P.P#...#...#....P#.#..PP...#P.P#P#...#.#P....#...#...#...#.#.#...#.#..P#.#..PP..P#.....#.#.#P..#P..#...#P.P#.#.#...#.#...#.....#...#.#.#..P#.#...#P...P#.....#
|
||||
#P#.#.#.#.###.#.###.###.###.#####.#######.#.#.#.#.#.#.#######.#.#####.#.###.###.#.###.#.#.#.#.#.###.#P#.#.###.#.###.#.#####.#######.#.#######.#######.#.#P#.#.###.#.###.###.#.#.###.###.#.###.#########.#
|
||||
#.#.#...#.#...#.#.#...#P#P..#P..#.....#...#P#..P#.#.#...#.......#P...P#..P#.#...#P..#.#...#..P#P.P#.#.#P#.#.#.#.#...#P....#..P#..P#.#...P...#.....#.#.#..P#.#P....#.P.#...#P#P...P..#P..#P#...#...#.....#
|
||||
#.#.###.#.#.###.#.#.#.#.#.###.#.#####.#.###.#####.###.###.#######.#.#####.#.#######.#.###.#########.#.###.#.#.#.###P#####.###.#.#.#.#######.#.###.#.#.#####.#########.###.#P#########.#.#.#.#.#.#.#.#####
|
||||
#P#...#...#...#.#...#.#...#...#.#..P..#...#...#...#...#P...P..#...#.#P....#......P#...#..P#..P#.....#..P#.#...#...#P#...#.#P#...#.#.#.....#...#P#P..#P...P#.#...#.....#P..#P#.#P...P#P#...#.#P#P#P..#..P#
|
||||
#####.#.#######.#.###.###.#.###.#.#######.###.#.###.#.#.#######.#####.#########.#####.#####.#.#.#######.#.#.#####.#.#.#.#.#.#####.#P#.###.#####.###.#####.#.###.#.#####.###.#.#.###.#.#####.###.#####.###
|
||||
#P....#P#...#..P#...#P.P#.#.#.#.#.#P..#P.P#P..#...#.#P#..P#....P#.....#.......#..P....#.....#.#...#P.....P#..PP...#..P#..P#....P#.#.#...#.#.#P....#..P#.#.#...#.#...#.........#..P#P#...P...#...#.#....P#
|
||||
#.###.###.#.#.#########.#.#P#.#.#.###.#.###.#####.#.#.#.###.#####.#####.#####.#####.###.#####.###.#########################.#.###.#.#.###.#.#.###.###.#.#.###.#.###.#############.#.#######.#.###.#.###.#
|
||||
#P#P.P#...#.#.#...PP...P#.#.#P....#...#.#P..#P......#.#.#...#..P..#..P#..P..#.#..P#P..#.#..P#..P#...P..P#.#.........#P......#.#...#.#.#..P#...#P..#P..#P#...#.#...#P..P.P....P....#...#PP...#.#P#...#...#
|
||||
#P#####.###.#.#.#########.#.#######.#.#.#.###########.#.#.###.#####.###.###.#.#.#.#####.###.###.#.#####.#.#.###.###.###.#.###.#.###.#.#.#####.#.###.###.#.#.#.###.###################.#######.#.#.###.###
|
||||
#.#.....#.#...#...#...#...#...#.....#P#P#.#.........#.#.#...#...#P..#....P#P#P#.#P...P#.#...#...#P...P#.#....P#...#..P#P#.#P#.#.#P.P#.#.....#.#...#.....#P#.#P..#.......#..P....PP.P#...#P..#P#P..#.#...#
|
||||
#.#.#####.#######.#.#.#.#####.#.#.#####.#.#.#######.###.###.###.###.#.#####.#P#P#####.#.#.###.#########.#########.###.###.#.#.#.#.###.#####.#P###.#.#####.#.###.#.#.###.#.###.#####.###.#.#.#.###.#.###.#
|
||||
#.#.#......P......#.#.#.......#.#.......#...#....P#...#.#.....#..P#...#P....#P#...#P#...#.#...#....P...P#P.....P.P#....P.P#P..#.#.....#P....#.#...#.#..P..#.#...#P#.#...#..P#P#...#.#...#.#.#..P#...#P..#
|
||||
#.#.#.#.###########.#.#########.#############.#.#####.#.#.#######.#.###.#####.#.#.#.#####.#.#####.#######.#########.###########.#.#####.#######.###.#.#####P#.#####.#.#######.#.#.#.#.###.#.###.#####.#.#
|
||||
#...#.#PPP#.......#.#.........#.#..P...P.PP...#.#P....#.#.....#...#..P#.#P#...#.#.#..P#P..#...#...#P#P.P#.....#PP...#....PP...#.#...#P.P#..P....#...#P.P.P#.#P#.....#P..#...#P#.#...#P#...#..P#P....#P#.#
|
||||
#.#######.#.#######.###.#######.#.#############.#.#####.#####.#.#######.#.#.#####.#.###.#.###.#.###.#.#.#.###.#######.#######.#.#####.###.#######.#######.###.###.#####.#.#.#.#.#####.#.#####.#####.#.#.#
|
||||
#.........#..P........#...........#..P.P.......P#..P.......P#P......P...#P........#....P#.......#....P#.....#......P.....PP.#.P.......#.....PP.P......P.#P........#PP....P#P.P#....P#P....P.#.........#..
|
||||
#########################################################################################################################################################################################################
|
101
2024/day18_the_ring/tests/challenge3
Normal file
101
2024/day18_the_ring/tests/challenge3
Normal file
|
@ -0,0 +1,101 @@
|
|||
###########################################################################################################################################################################################################################################################
|
||||
#...............#.......#...#.......#.........#...#...#...#...#.......#.......#...#.........#.....#.......#.........#...#.....#...........#.........#.......#...............#.....#...#.....#.#............P#.......P...#.............#.........#.......#.#
|
||||
#.###.#######.#.#####.#.#.#.#.###.#.#.#######.#.#.###.#.#.#.#.#.###.#.#.#.###.#.#.#######.#.#.###.#.#.###.#.#######.#.###.#.###.#.#######.#.#.#####.#.#####.#.#############.#.###.#.#.#.###.#.#.#########.#.#.#.#######.#.#.###.#######.###.#####.###.#.#.#
|
||||
#...#....P#...#.......#.#P#...#...#...#.....#.#.#...#.#.#...#.....#.#.#.#.#.#...#.........#...#.#.#.#.#.....#.....#.#.....#...#.#.#.......#.#.#.#.....#...#...#...........#.#.#.#.#.#...#...#.#.#...#.....#.#.#.#.....#.#.#..P#.#...#...#.#.......#...#...#
|
||||
###.#######.###########.#######.#######.#.#.#.#.###.#.#.###########.###.#.#.###################.#.###.###########.#.#######.#.#.#.#.#######.#.#.#.#######.###.#.#########.#.#.#.#.#.#####.###.#.###.#.#####.###.###.###.#.###.###.#.#.###.#########.#####.#
|
||||
#...#.......#.........#.......#.#.....#.#.#.#...#...#...........#...#...#.#.......#.....#...#...#...#...#.........#.......#.#...#.#.#....P..#.#.....#...#.....#P#.......#.#...#...#.#...#.....#...#.#...#.#...#...#....P#...#...#.#...#.....#.....#.#...#.#
|
||||
#.###.#######.#####.#########.#.#.###.#.#.#######.###############.###.###.###.#####.#.#.#.#.###.###.#.#.#.###.###.#######.#.#####.#.#########.#######.#.#######.#.#####.#.#####.###.#.#.#####.###.#.###.#.###.###.#########.###.#.#######.#.###.#.#.#.###.#
|
||||
#.#...#.....#P#...#.......#...#.#.#.#.#.#.....#...#...#.........#.....#...#P..#.....#.#...#.#...#...#.#.#.#.#.#...#...#...#...#...#.....#..P..#.......#....P#...#.....#...#.....#...#.#.#...#...#...#...#...#...#.....#...#...#...#.......#...#.#.#.#.....#
|
||||
#.###.#.#.###.#.#.#######.#.###.#.#.#.#.###.###.###.#.#.#######.#######.###.###.#####.#####.#.#.#.#####.#.#.#.#####.#.#.###.###.#######.#.###.#.###########.#.#######.#.#######.#.#.#P#.#.#.#######.#.###.#####P#.###.#.#.###.#####.#########.#P###.#.#####
|
||||
#.....#.#.....#.#.......#...#.....#.#.#..P#.#...#...#.#.#...#.....#.....#.#...#.#.....#P..#...#.#.#.....#...#...#...#.#...#.#...#...#...#.#...#...#.....#...#.#...#...#.#.....#.#.#...#...#.........#.#.#.....#.#.#.#...#..P#.......#.....#.#...#...#...#.#
|
||||
#######.#######.###.###.#####.#####.#.#####.#.###.###.#.#.#.#####.#.#####.#.#.#.#.#######.#####.#.#.#######.###.#.###.###.###.###.#.#.###.###.###.#.#.#.#.###.#.#.#.#####.###.#.#.###################.#.#.#.###.#.#.#####.#.###.#####.###.#.###.#.#####.#.#
|
||||
#.....#.#.....#...#.#...#...#.......#.....#...#...#.#.#...#.....#.#.#.......#...#.#P..P...#.....#...#.#.....#...#.#.#.#..P#...#...#.#...#...#P#...#.#.#.#.......#.#...#...#P#.#.#...#.#.......#.....#.#...#...#.#...#P..#.#...#.#.....#...#...#.#.#...#.#.#
|
||||
###.#.#.###.#.#.###.#.#####.#######.#####.#.#####.#.#.###.#####.#.#.#.#########.#.###.###.#.#########.#.#####.###.#.#.#.###.###.###.###.#.#.###.#####.###########.###.#.###.#.#.###.#.#.###.#.#.###.#.#.#####.#.###.#.#.#.#####.#.#####.###.#.#.#.#.#.#.#.#
|
||||
#..P#.#.#...#.#.#P..#.....#.....#.......#.#...#...#.#...#....P#.#.#.#.#.......#.#.#...#...#.#P........#.#...#...#.#.#.#.#P..#....P#...#.#.#...........#.......#.#...#.......#P#.#...#...#...#...#...#.#P....#...#.#...#.#.......#...#...#..P#.P.#.#.#.#.#.#
|
||||
#.#####.#.###.###.#######.###.###.#######.###.#.###.###.#####.#.#.#.#.#.#####.###.#.#####.#.#####.###.#.#.#.###.#.#.#.#.#.###########.#.#####.#######.#.#####.#.###.#########.#.#.#######.#######.###.#####.#####.#####.###########.#.###.#######.#.#.#.#.#
|
||||
#.#...#.#.#.#.#...#.....#.#...#.....#.....#.....#.#.....#.....#.#...#.#.#...#.....#.....#.#.#...#...#.#...#.#.#.#.#.#.#.#.........#...#.....#...#...#.#...#...#P..#.#.#.......#.#...#...#.#.....#.#...#...#...#.......#.........#...#...#.#.....#.#.#.#...#
|
||||
#.#.#.#.#.#.#.#.###.#####.#.###.#####.###########.#.#####.#####.#######.#.#############.#.#.#.#.###.#.#####.#.#.#.#.#.#.#.#######.#.#######.#.###.#.#####.#.###.#.#.#.#.#######P###.#.#.#.#.#.###.#.#####.###.#.#####.#####.#####.#####.#.###.###.#.#####.#
|
||||
#...#.#...#.#...#.........#.....#....P#.....#.......#.#.....#...#.......#.#...........#.#.#...#.....#.#...#.#.#...#.#P#.#.#..P....#.......#.#.#...#.......#.#...#.#...#...#.....#.#.#.#...#P#.....#.#.......#.#P....#..P#...#...#.#.....#.....#...#.....#.#
|
||||
#.###.#####.#####.#########.#####.#####.###.###.#####.#.#####.###.###.###.#.#####.###.#.#############.#.###.#.#####.#.#.###.#######.#####.#.###.###########.#.#.#####.###.#.#####.#.#.#####.#######.#.#.###.#.###.#.#.###.###.#.#.#.###########.#######.#.#
|
||||
#.#.....#.......#.#.....#...#...#...#...#.#...#...#...#...#...#.....#.#...#.#...#.#...#.......#.......#.#...#.......#...#...#.....#.#...#.#.#...#.......#...#P#.#...#.#.#.#.#.....#...#...#.....#...#.#...#.#...#.#.#.#...#.#.#...#.#...........#.......#.#
|
||||
#.#.#####.#####.#.#.###.#.###.#.###.#.###.###.###.#.#####.#.#########.#.#.#.#.#.#.#.#####.#####.#######.#.###.#.#########.###.#####.#.###.#.#.#########.#.#####.#.#.#.#.#.#.#####.#.###.#.#######.###.###.#.###.#.#.###.###.#.#####.#.#############.#.###.#
|
||||
#.#....P..#...#.#.#.#...#...#.#...#...#.....#...#.#.......#...#...P...#P#...#.#...#.......#...#.#.#.....#...#.#.#.........#...#...#.#...#...#.....#...#.#.....#..P#..P..#.#.....#.#.#...#...#.....#.#.#...#.#...#.#...#.#...#...#.#.#.#...#...#.....#.#...#
|
||||
#.#########.#.#.#.#.#######.#.###.#########.###.#.###########.#.#############.#############.#.#.#.#.###.###.###.#.#######.#.#.#.#.#.###.#####.###.#.#.#.#####.###.#######.#####.#.#.#.#####.#.#####.#.#.#####.###.###.#.###.###.#.#.#.#.###.#.#.#.###.#.###
|
||||
#...#...#...#...#.#.....#...#...#.............#.#.............#.#...........#...............#...#.#...#...#...#...#.......#.#.#.#...#.....#.#...#.#.#.#...#.#...#...#P#...#.....#...#.....#...#.....#.#.....#.#...#.#.#.#...#.#.#.#...#.....#...#...#.#...#
|
||||
###.#.#.#.#####.#.#.###.#.###########.#.#.#####.#.#############.#.#########.#.#######.###########.###.###.###.#####.#######.#.#.#####.###.#.###.#P#.#.#.#.#.###.###.#.#.###.#####.#######.#####.###.#.#####.#.###.#.#.#.#.#.#.#.#.#####.###########.#####.#
|
||||
#...#.#..P#.#...#.#...#...#.........#.#.#.#...#.#.#.........#...#.#.....#...#...#...#.#.......#...#...#P#...#...#...#.#...#.#...#...#...#.#.....#...#.#.#.....#.#.....#...#.#...#...#.#...#.....#.#.#...#...#...#...#.#...#...#.#.....#.#...#P......#.....#
|
||||
#.###.#####.#.###.#######.#.#.#####.###.###.#.#.#.#.#######.###.#.#.###.#.#####.#.#.#.#.#.###.#.#.#.###.#.#####.#.###.#.#.#.#####.#.#.#.#.#######.###.#.#######.#######.#.#.#.#.###.#.#.###.#####.#.###.#.#####.###.#.#####.###.#.###.#.#.###.#######.#####
|
||||
#P#...#...#...#.#.......#.#.#.....#.....#...#...#.#..P..#.#...#.#.#...#.#.#.....#.#.#.#.#.#...#P#.......#.#.....#..P#...#...#....P#...#.#.......#.#.#.#.......#.......#.#.#.#.#.#...#.#.#...#.....#.....#.....#...#P#.......#...#.#.#.#.#...#P........#...#
|
||||
#.#.###.#.#.###.#######.#.#######.#####.#.#######.#####.#.###.#.#.###.###.#.#####.#.#.###.#.#############.#.#####.#.#P#################.#######.#.#.#.#####.#.#######.###.#.#.#.#.###.#.#.#####.#.###########.###.###########.###.#.#.#.###.###########.#.#
|
||||
#.#...#.#.#.......#...#.#.........#.....#...#P..#.#.#.....#...#.#..P#.#...#.P...#.#.#.....#.........#...#.#...#.#.#.#.#P................#.....#.#.#.#.#...#.#.......#.....#.#.#...#...#.#...#...#...#...#.#.....#.....#.......#.....#.#...#..P#.........#.#
|
||||
#.###.#.#######.###.#.#.###########.#######.#.#.#.#.#.#####.###.###.#.#.#######.#.#.###.###########.#.#.#.###.#.#P#.#.###.###############.###.#.#.#.#.#.#.#.#.#####.#######.#.#####.###.###.#.#####.#.#.#.#.#########.#.###########.#.###.#.###.#####.#.###
|
||||
#...#.#.........#...#...#P....#...#...#...#.#.#.....#...#...#...#.....#.#...#...#.#...#.#...#.....#...#.....#.#...#.#...#...#.............#P..#.#...#.#.#.#P#.....#.#...#...#.....#...#.#.#.#...#...#.#...#.#...P.....#.....P...#...#...#.#.....#...#.#...#
|
||||
#####.#.#########.#######.###.#.#.###.###.#.###########.#.#####.#.#####.#.###.###.###.###.#.#.###.#########.#.#####.###.#.#.#.###.#########.###.###.#.#.#.#####.#.#.###.#.#######.###.#.#.#.###.#.###.###.#.#.#################.#.#####.#P###.###.#.###.#.#
|
||||
#...#.#.#.......#.#.....#...#.#.#...#.....#.............#.#...#.#.#P#...#.....#.#...#...#.#.#.#...#.........#.#...#...#.#.#P#.#...#...#.......#...#P#...#.#...#.#.#.....#.......#...#.#.#.#...#.#...#.#...#.#.#.................#.#.....#...#...#.#...#.#.#
|
||||
#.#.#.#.#.#####.#.#.###.#.#.#.#.#.#.#####.###############.#.#.#.#.#.#.###.#####.###.###.#.#.#.#.###.#########.#.#.###.#.###.#.#.###.#.#######.###.#######.#.#.###.#####.#######.###.#.#.#.###.#.###.#.#.###.#.#.###################.###.###.###.#.###.###.#
|
||||
#.#...#.#.#...#.#...#...#.#.#.#.#.#...#...#.....#.........#.#...#.#.#...#.....#...#.#.#...#.#.#.......#.......#.#...#.#...#.#.#.....#.....#...#...#.......#.#.....#...#.#.#.....#P#...#.#.....#.#.....#.#.#.#.#.#.........#P........#.#.#.#.#..P#.#P#.#...#
|
||||
#.#####.#.#.#.#.#####.###.#.###.#.#####.###.###.#.#########.#####.#.###.#####.###.#.#.#####.###########.#######.###.#.###.#.###.#########.#.###.###.#######.#######.#.#.#.#.#####.#.###.#.#####.#######.#.#.#.#.###.###.#.#######.###.#.#.#.#####.#.#.#.#.#
|
||||
#.#.....#...#.#.....#...#.#.#...#.#.....#...#.#.#.#.........#.....#...#.#...#...#.#.#...#.#...#...#...#.......#.#.#...#.#.#...#.#.....#...#.#.#.....#P..#...#P......#.#...#...#.....#...#.#...#.....#.#.#.#.#.#...#.#...#.......#...#.#.#.#.#.....#...#.#.#
|
||||
#.#.#####.#####.#######.###.#.###.#.#####.#.#.#.#.###.###.###.#####.#.#.#.#.###.#.#.#.#.#.###.#.#.#.#.#######.#.#.#####.#.###.#.#.#.###.###.#.#########.#.#.#####.#####.#####.#.#####.###.#.#.#.###.#.#.#.#.#.###.###.#########.#.#.#.#.#.#.#.#####.###.#.#
|
||||
#.#.#.....#.....#.....#.P.#...#.#.#.#...#.#.#...#...#...#.#...#...#.#.#...#...#...#...#...#.#...#.#.#...#...#...#.......#.....#...#.#...#P#.#...........#.#...#...#.....#...#.#...#...#.#...#.#...#.#.....#.#...#...#.....P.#...#.#.#.#...#.#.#...#...#.#.#
|
||||
#.###.#####.#####.###.###.#.###.#.#.#.###.#.#######.#####.#.###.#.###.#######.###########.#.#####.#.#.#.###.#####.#.#################.###.#.#.#######.###.###.#.###.#####.#.#.###.#.###P#####.###.#.#####.#.###.###.#.#####.#.#####.#.#.###.#.#.#.###.#.###
|
||||
#.#...#...#.........#...#.#P#...#...#.....#.#.....#.....#.#.....#...#.#.......#.......#...#...#.#.#.#.#.....#.....#.......#.........#...#...#.....#...#.....#.#.....#....P#.#.P.#.#.#.......#.#...#.....#.#...#.....#.#.....#.#.....#...#...#.#.#.....#...#
|
||||
#.#.###.#.#############.#.#.###.###########.#.###.#####.#.#########.#.#.###.###.#####.#.###.#.#.#.#.#.#####.#.#########.###.#.#####.###.#.#####.#.#####.#####.#####.#.#####.###.###.#.#.###.#.#########.#.###.#########.#####.#.#####.###.###.#.#########.#
|
||||
#.#...#.#.......#.......#.#.....#.#.......#.#.#.......#.#...........#.#...#.#...#...#....P..#...#.#.#.#...#.#.#...#...#.....#...#.#...#.#.#...#.#.......#.....#...#.#...#.....#...#.#.#...#P#.#.......#.#.#...#.#.....#.#...#.#.#...#.#...#P..#.#.......#.#
|
||||
#.###.#######.###.#####.#.#####.#.#.#.###.#.#.#######.#.#####.#######.###.#.#.###.#############.#.#.#.###.#.#.#.#.#.#.#########.#.###.#.#.#.#.#######.###.###.#.#.#####.#.###.###.#.#.###.###.#.#####.#.#.#.#.#.#.#.#.#.#.#.#.#.###.#.#.#####.#.###.###.#.#
|
||||
#...#.......#.#...#.....#.#...#.#...#...#...#...#.....#.#...#.#.......#...#.#.#...#.........#.#.#...#...#.#.#...#...#.......#P..#...#.#.#.#.#.......#.#...#...#.#.....#.#...#.#...#.#...#.#.....#P......#.#.#.#...#.#...#.#.#.#...#...#...#...#...#.#.#P#.#
|
||||
#.#.#######.#.#.#########.#.#.#.#######.#######.#.#####.#.#.#.###.#.#.#.#####.#.###.#######.#.#.#######.#.#.###############.#.#####.#.#.#.#.#######.#.#.#######.#####.#.###.###.###.###.#.#.#######.#######.#.#####.#.###.#.#.###.#.#####.#.#####.#.#.#.#.#
|
||||
#.#.#.....#.#.#.......#...#.#...#.......#.......#.#.....#.#.#...#.#.#.#.....#.#.#...#.....#.#.#.#.....#.#...#...#.#.......#.#.....#.#.#.#...#.....#.#.#.#.....#...#.#...#.#.....#...#.#.#.#.#.#...#.#.......#.#.....#.#...#.#.#...#.#.#...#.#...#...#.#.#.#
|
||||
#.###.#.###.#.#######.#.###.#####.#####.#.#######.###.###.#.###.###P#######.#.#.#.###.###.#.#.#.#.#####.#.###.#.#.#.#.#####.#####.#.#.#.#.###.###.#.#.#.#.###.###.#.#####.#######.###.#.#.#.#.#.#.###.#######.#.#####.#.###.#.#.###.#.#.###.#.#.#####.#.#.#
|
||||
#.....#.....#...#...#...#.....#...#.....#.#.....#...#.....#...#...#.......#...#.#...#...#...#.....#...#.#.#...#.#.#.#.....#.#...#.#.#...#.#...#P..#.#.#.#...#...#.#.......#.......#.....#.#...#.#.#...#.....#...#.....#...#.#...#.....#...#...#.#P........#
|
||||
#.###########.#.#.#.#########.#.#.#.#####.#.###.###.#.#######.###.#######.#####.###.###.#####.#####.#.#.#.###.#.#.#.#####.#.###.#.#.#####.#.###.###.###.###.###.#.#.###.#.#######.#.#####.###.#.#.#.#######.#####.#######.#.#.###########.#.###.#########.#
|
||||
#.#.....#.....#.#.#.#.......#.#.#.#.#.....#..P#.#...#.#.......#...#.....#.........#.#.....#...#.....#...#.#...#...#.....#.......#.#.......#...#...#.....#...#.#...#.#...#...#.....#.P...#....P#.#...#.....#...#...#...#...#.#.#...#.......#..P#.....#...#.#
|
||||
#.###.###.#####.#.#.#.#.###.#.###.#.#.#####.###.#.#####.#########.#.###.#.#.#######.#####.#.###.#########.#.#####.#####.#########.###########.###.###.###.###.#######.#####.#.#########.#######.#####.###.#.###.###.###.###.#.#.#.#.#######.#######.#.#.###
|
||||
#...#...#.....#...#...#.#...#P....#.#.#P....#...#...#...#.......#...#.#...#.#...#...#...#P#.#...#.......#...#.......#...#P..#...#.#....P......#...#...#...#.........#.#.#...#.#.....#...#...#.#.......#.#.#..P..#...#...#.#.#.#.#...#...#...#.....#...#...#
|
||||
###.###.###.###########.#.#########.#.#######.#####.#.#######.#.#####.###.###.#.#.#.#.#.#.###.###.#####.#####.#######.#####.#.#.#.#.###########.###.###.###.#######.#.#.#.###.#.#####.###.#.#.#########.#.#####.###.#.###.#.#.#P#####.#.#.###.###.#######.#
|
||||
#.#...#.#...#...#.......#...#.....#.#.#....P#.....#.#.#.....#.#...#.......#...#...#.#.#.#.#...#.......#...#.....#...#.#.....#.#...#.....#..P#...#...#.#.#.....#..P..#.#...#...#....P#.....#.....#.......#.....#.....#.#...#.#P#.#.#...#...#.#.#...........#
|
||||
#.###.#.#.###.#.#.#########.#.###.#.#.#.###.#.#.###.#.#.###.#.###.###.#####.#######.#.#.#.#.#.#.#########.#.#####.#.#.#.###.#.#########.#.###.###.###.#.###.#.#####.#.#.###.#######.###########.###.#.#######.#####.#.#.#.#.#.#.#.#.#######P#.###########.#
|
||||
#.....#...#...#...#...#...#...#.#.#.#.#...#.#.#.#...#.....#.#.#.#...#.#...#...#.....#.#.#...#P#.#...#.....#...#...#...#...#.#.#.......#...#...#...#...#...#.#.....#.#.#.....#.........#.........#...#.#.....#.#.....#.#.#.#.#.#.#.....#...#.#...........#.#
|
||||
#.#######.#.#######.#.#.#.#####.#.###.###.#.#.#.#.#########.#.#.###.#.#.#.###.#.#####.#.#######.#.#.#.###.#####.#########.###.#.#.#######.#.#####.###.###.#.#####.#.#.#######.#.###.###.#########.#####.###.#.#.#####.###.#.#.#.#####.#.#.#.#########.#.###
|
||||
#.#.....#.#.#.#.....#...#.......#...#.#...#.#.#.#...........#.#.....#.#.#.....#...#...#.#.......#.#...#...#.....#........P#...#.#.........#.....#.......#.#.#...#.#...#...#.#.#...#.#...#...#.........#...#.#.#.#.....#...#.#.#...#..P#.#.......#...#.#...#
|
||||
#.#.###.###.#.#.#############.#.###.#.#.###.###.#############.#.#######.#.#########.###.#.#######.#####.###.#####.#####.###.#.#.###############.#######.#.###.#.#.#####.#.#.#.###.#.#.###.#.#.#######.###.#.#.#.#.#####.#.#.#####.#.###P###.#####.#.#####.#
|
||||
#...#P#.....#.....#.....#...#.#...#..P#.#.#.#...#.........#...#.#...#...#.#.........#.#...#...#...#......P#.....#.#.....#...#P#.#.........#...#.#...#...#.....#...#.....#.#.....#.#.#.#...#...#.........#.#...#.#...#...#.#...#...#.....#.#.#.....#.....#.#
|
||||
#####.#############.###.#.#.#.###.#####.#.#.#.#.#.###.###.#.###.#.#.#.###.#.#########.#####.#.#.###############.###.###.#.#####.#.#.#####.#.#.#.###.#.#############.#####.#####.#.###.#########.#######.#.#########P#.#.#####.#.#########.#.#.#########.#.#
|
||||
#.....#...........P.#.#.#.#.#...#.......#.#.#.#.#...#...#...#.#...#...#...#.....#.......#...#.#.#.......#.....#.....#...#.....#.#.#.#.#...#.#.#...#.#...#.#......P..#...#.....#.#...#.#.......#.#.....#.#.........#...#.#.....#...#...#P....#.........#...#
|
||||
#.#.###.###.#########.#.#.#.#.#####.###.#.#.#.#.#######.#####.###.#############.#######.#.###.#.#.#####.#.###.#.#############.#.###.#.#.#####.###.#.###.#.#.#####.###.#.#####.#####.#.#.#####.#.#.#.#.#.#########.#####.#.###.###.#.#.###.###########.###.#
|
||||
#P#.....#.#...#..P........#.#.#...#...#.#.#...#.........#.......#.#...........#...#...#P....#.#.#.#...#...#.#.#.#....P..#.....#.....#.#........P#.#.....#.#.....#.....#.#...#.....#.....#.P.#.#.#.#.#.#.#.....#.#...#...#...#...#.#.#...#.....#.....#...#.#
|
||||
#.#######.###.#############.###.#.#####.#.#.#################.#.#.#.#######.#.###.#.#.#######.#.#.#.#.###.#.#.#.#.#####.#.###########.#########.#.###.###.#####.#######.#.#.#####.#######.###.#.###.###.#.###.#.#.###.#####.#.###.#.###.#####.#.###.###.###
|
||||
#.#.......#.#...#.......#P#.#...#.......#...#.............#...#.#.#.#P..#...#..P#...#...#...#.#.#.#.#...#...#...#.#.....#.#...........#.........#...#.....#.....#.....#.#.#...#...#...#...#...#...#.....#...#...#.....#.....#.#...#...#.#.....#.#.#...#...#
|
||||
#.###.###.#.###.#.#####.#.#.#.#.#######.#####.###########.#.###.#.#.###.#.#####.#######.#.#.#.#.#.#.###.#########.#####.#.#.#########.#.###########.#######.#####.###.#.#.###.#.###.#.###.#.#####.#.#####.#.#.#########.#.#####.#####.#.#.#####.#.###.###.#
|
||||
#.....#P#.#...#.#...#...#.#.#.#.#....P#.#.....#...........#.#.#.#.#...#.#.....#.....#.#...#.#.#...#...#.....#...#.#...#...#.........#.#.......#...#.....#...#...#.#P....#.#P#.#.#...#...#.........#.#...#.#.#.#.........#.#...#.#.....#.#.#P..#.#...#.....#
|
||||
#######.#.#.#.#.#.###.###.#.#.#.#.###.###.#####.###########.#.#.#.###.#.#####.#####.#.#####.#.#######.#####.#.#.#.#.#.###########.###.#######.#.#.#####.#.###.#.#.#######.#.#.#.#.#.###.###########.#.#.###.###.###########.#.#.#.#####.#.#.#.#.#.#######.#
|
||||
#.......#.#.#.#...#..P#...#...#.#P#.#...#...#...#.....#...#.#...#...#...#...#...#...#...#...#.#...P.#.#.......#.#...#.........#...#...#.......#.#.....#.#...#.#.#...#.....#...#P#P#...#.....#........P#.....#...#.....#.....#...#...#...#...#.#.#.........#
|
||||
#.###.###.#.#######.###.#.###.###.#.###.###.#.###.###.#.#.#.#######.###.#.#.###.#.###.#.#.###.#.###.#.#########.#.#########.#.#.###.#.#.#######.#####.#.###.#.#####.###.#######.#####.#####.###############.#.#.#.###.#.#########.#.###.#######.#.#########
|
||||
#...#.#...#..P....#.#...#.....#...#...#.....#...#...#...#P..#.....#.#.#.#.#...#.#..P#P#.#.#...#.#...#.#.......#.#.........#.#.#.#.#.#.#.....#...#...#...#.#...#.....#...#...P.#...#...#...#.#.....#.........#.#.#...#...#.....#...#...#.........#.#.....#.#
|
||||
###.#.#.#########.#.###########.###.#.#########.#.#.#########.#.###.#.#.#####.#.###.###.#.###.#.#.#.#.#.#####.#.###.#######.#.#.#.#.###.#####.###.#####.#.###.#.#####.###.###.###.#.###.#.#.#.###.#####.#####.#####.#####.###.#####.#.###########.#.###.#.#
|
||||
#.#.#...#.........#.....#.......#...#...#P..#...#.#...........#..P#.#.#.#.....#.#...#...#...#...#.#.#...#...#.#.#...#.......#.#.#.#.....#...#.#...#.....#...#.#...#.....#...#.....#.....#.#.#...#.....#.#...#.....#.#.....#...#...#.#.#...#.......#...#...#
|
||||
#.#.#######.#####.#####.#.#######.#######.#.#.###.###############.#.#.#.#.###.#.###.#.#####.#####.#.#####.###.#.#####.#########.#.#######.#.#.#.#.#.#######.#.###.###.#.###.#######.#####.#.#.#.#####.#.###.#####.#.#.#####.###.#.###.#.#.#.#######.#.#####
|
||||
#...#.......#...#.....#.#.#.....#.#..P....#.#.#...#.........#.....#.#.#...#.#.#P..#.#.....#.#.....#.....P.#...#.....#.........#.......#...#..P#.#.....#...#.#...#...#.#...#.#.....#.....#.#.#.#.#...#.#.#.....#...#..P#...#.....#.....#.#.#...#.#...#.....#
|
||||
#.###.#####.#.#.#######.#.###.#.#.#.#######.#.#.###########.#.#####.#.#####.#.###.#P#####.#.#.###########.#.#######.#.#######.#####.###.#############.#.#.#.###.###.#.#.#.#.#.###.###.###.#.###.#.###.#.#.###.#.#########.#############.#.###.#.#.#######.#
|
||||
#.....#...#.#.#...#...#.#.....#...#.#.....#...#.#...........#.....#.#.#.......#...#..P....#.#...#.......P.#.#....P#.#.......#...#...#...#.....#.....#...#.#...#...#.#.#.#.#.#...#...#.#...#.#...#.....#...#...#.............#...........#...#.#...#.....#.#
|
||||
#######.#.#.#.###.#.#.#.#########.#.###.#.#####.#.#########.#####.#.#.#.#######.#########.#.#.#.#######.###.#.###.#.#########.#.#.###.###.###.#.###.#####.#.###.###.#.#.###.#.#.###.###.###.#.###.#########.#######.#######.#.#.#########.###.#.###.#.###.#
|
||||
#....P#.#.#.#.#.....#.#P..........#...#.#.#...#...#.....#...#...#.#...#...#.....#.....#...#.#.#.......#...#.#.#.#.#.......#...#.#...#.....#...#.#.#...#.#...#...#...#.#.....#.#.#.#...#...#...#.#.#...#...#...#.....#.......#.#.....#...#.#...#...#.#.#...#
|
||||
#.###.#.#.#.#.#######.#############.#.###.#.#.#####.###.#.#####.#.###.###.#.#####.###.#####.#.#####.#.###.#.#.#.#.#######.#.###.###.#######.###.#.###.#.###.#.###.###.#########.#.###.###.#####.#.#.#.#.#####.#.#####.#######.#####.#.#.###.#####.###.#.###
|
||||
#.#.....#.#.#...#...#.....#.......#.#.#...#.#.......#...#.......#.......#.#...#...#.#P......#.#...#.#.#.#.#.#...#.....#...#...#...#.#.....#.....#...#.#..P#.#...#.#.#...........#..P#.#...#.....#.#P#.#.......#.#...#.#...#...#...#...#...#.#.........#...#
|
||||
#.#######.#####.#.#######.#.#####.###.#.###.###.###############.#######.#.###.#.###.#########.#.#.###.#.#.#.###.#.#.###.#####.###.#.#.###########.#.#.###.#.###.#.#.#############.#.#.#.#######.#.#.#.#######.#.#.#.#.###.#.###.#.#######.#.###.#########.#
|
||||
#.......#.....#.#..P.....P..#.......#.#...#.#.#.#.................#...#.#.#.#...#...........#.#.#...#.#...#...#.#.#.#...#.....#...#.#...#.........#.#.P.#.....#.#.#.....#...P...#.#.#...#...#...#...#.......#.#.#.#.#...#.#...#.#.......#.#...#.#.#.....#.#
|
||||
#.#####.#####.#.###################.#.#.#.#.#.#.#.#################.#.#.#.#.#######.#######.###.###.#.#.#####.#.#.###.###.#####.###.#.#.#.#.###########.#######.#.#####.#.#####.#.#.#####.#.#.#############P###.#.#####.#.###.#.#######.#.###.#.#.#.###.#.#
|
||||
#...#P#...#.#...#.....#.........#...#.#.#.....#...#P#P......#...P...#.#.#...#.......#.#...#.#...#...#.#.#...#.#P#.....#....P..#.#...#.#...#.#.....#...#.........#.....#.#...#.#...#...#...#.P.#...........#.....#.....#.....#.#.....#.......#.#...#.#.....#
|
||||
###.#.###.#.#.###.###.#.#######.#.###.#########.###.#.#####.#.#######.#####.#.#######.#.#.#.#.###.###.#.#.###.#.#############.#.#.#######.#.#.###.#.#.###############.#.###.#.#######.#.#.###.#.#####.###############.#####.#.#####.#########.###.#.#####.#
|
||||
#.#.#...#.#...#...#.#.#.....#P#.#.....#.......#.....#.#.#...#.#.....#...#...#.....#.P...#.#.#.#...#...#.#P..#.#...#.#.........#.#...#...#.#.....#...#.....#.......#...#.............#..P#...#.#.#...#.............#.....#...#...#.#...........#P#.#...#...#
|
||||
#.#.#.#.#.#####.###.#.#####.#.#.#.#####.#####.#######.#.#.###.#.###.###.#.#######.#.#####.#.#.#.#####.#.###.#.###.#.#.#.#######.###.#.#.#####.#######.###.#.#####.#.#############.#########.###.#.#.###.#######.#.#.#.###.#####.#.#############.#.###.#####
|
||||
#.#...#.#.......#...#...#.#...#.#.#.....#...#.......#...#.#...#...#...#.#.........#.#...#...#.#...#...#.....#.#P..#...#...#.......#...#.#...#.#.....#P#...#...#.#...#.....#...#...#...#...#.....#.#...#...#.#...#...#.#.....#...#P......#.......#P..#.....#
|
||||
#.#####.#########.###.#.#.###.#.###.#####.#.#######.###.#.#.#########.#.###########.#.#.#####.###.#.#######.#.#.#########.#.###########.#.#.###.###.###.#.###.#.#.###.###.#.#.###.#.#.#.#.###.###.###.###.#.#.###.#####.#####.#####.###.#.###.#####.#####.#
|
||||
#.....#.....#.......#.#.....#.#...#.#.#...#.....#.....#.#...#.......#.#....P..#.....#.#.....#...#.#...#.....#.#...........#.#.........#.#.#.....#.#...#.#.#...#.#.#...#.#..P#...#.#.#...#...#.#...#P..#.#...#.#...#...#.#.....#...#...#..P..#.......#...#.#
|
||||
###.#.#####.###.###.#.#######.###.#.#.#.#.#####.#.#####.#####.#####.#.#######.#.#######.###.###.#.#.#.#####.#.#############.#.#######.#.#.#######.###.#.#.#.###.#.#.###.#######.###.#######.#.#.###.###.###.#.#####.#.#.#.#####.#.#.#######.#####.###.#.#.#
|
||||
#...#.....#...#...#.#.........#.#...#.#.#.#.....#.....#.......#.#...#.....#.#.#.........#.#.....#.#.#...P.#.#...#...#.......#.#.....#...#.#.........#...#.#.#.#...#.#.....#...#P....#.#.....#.#.#.#.#P......#...#...#...#...#...#.#.#.....#.#...#.....#.#.#
|
||||
#.#####.#####.###.#.###########.#####.#.#.#.#########.#########.#.#####.#.#.#.###########.#######.#.#####.#####.#.#.#########.#.#.#######.#.#.###########.#.#.#.###.#.#.#.###.#######.#.###.###.#.#.#####.#####.#.#########.#.#.#.###.###.###.#.#####.###.#
|
||||
#P#.....#...#...#.#...#...#.....#...#...#.#...#.....#.......#...#...#...#...#...#.......#...#.....#.....#.....#.#.#...........#.#.........#.#...#.......#.#.#...#...#P#.#.....#.......#.#...#..P#.#.#...#....P#...#.......#.#.#.#...#...#.....#...#...#...#
|
||||
#.#######.#.###.###.#.#.#.#.###.#.#.#####.###.#.###.#.#######.#.###.#.#####.#.###.#####.#.#.#.###############.#.#.#####################.###.###.#.#.#####.#.#####.#####.#####.#######.#.#####.###.#.#.#.###########.###.###.###P###.###.#########.#####.#.#
|
||||
#.........#.........#...#...#.....#.......#.....#P..#.........#.......#..P..#.........#...#....P..............#.........................#.....#...#.......#.............#.............#...........#...#...............#.........#.......#...............#.#
|
||||
###########################################################################################################################################################################################################################################################
|
5
2024/day18_the_ring/tests/sample1
Normal file
5
2024/day18_the_ring/tests/sample1
Normal file
|
@ -0,0 +1,5 @@
|
|||
##########
|
||||
..#......#
|
||||
#.P.####P#
|
||||
#.#...P#.#
|
||||
##########
|
9
2024/day18_the_ring/tests/sample2
Normal file
9
2024/day18_the_ring/tests/sample2
Normal file
|
@ -0,0 +1,9 @@
|
|||
#######################
|
||||
...P..P...#P....#.....#
|
||||
#.#######.#.#.#.#####.#
|
||||
#.....#...#P#.#..P....#
|
||||
#.#####.#####.#########
|
||||
#...P....P.P.P.....P#.#
|
||||
#.#######.#####.#.#.#.#
|
||||
#...#.....#P...P#.#....
|
||||
#######################
|
5
2024/day18_the_ring/tests/sample3
Normal file
5
2024/day18_the_ring/tests/sample3
Normal file
|
@ -0,0 +1,5 @@
|
|||
##########
|
||||
#.#......#
|
||||
#.P.####P#
|
||||
#.#...P#.#
|
||||
##########
|
6
2024/day19_encrypted_duck/Cargo.toml
Normal file
6
2024/day19_encrypted_duck/Cargo.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "day19_encrypted_duck"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
134
2024/day19_encrypted_duck/challenge.txt
Normal file
134
2024/day19_encrypted_duck/challenge.txt
Normal file
|
@ -0,0 +1,134 @@
|
|||
Part I
|
||||
|
||||
During the Tournament, the Order of the Golden Duck has opened its catacombs for exploration by contestants. As you navigate through narrow corridors, you come across a large chamber, well-lit by sunlight streaming in through small windows at its peak. In the center lies a stone tomb with a plaque in front of it:
|
||||
|
||||
= Sir Enigmatus Encriptus =
|
||||
|
||||
Devised a method to communicate without the risk
|
||||
of message interception by messengers or enemies
|
||||
during the Great RAM (Realm Allocation Mayhem) War
|
||||
|
||||
Around the tomb, there are many books placed on pedestals. You check a few of them. In addition to the descriptions of the heroic deeds and accomplishments of the Golden Duck Order, you also find a book describing the method of message encryption. It turns out to be very simple yet clever!
|
||||
The message is hidden on a grid of characters. To read the message, you need to perform a sequence of rotations on every rotation point on the grid according to the message key.
|
||||
To start, you need to understand the concept of a rotation point. Each cell on the grid has neighbouring cells (including diagonals). The number of neighbouring cells depends on whether the cell is in the corner (3 neighbouring cells), on the edge (5 neighbouring cells), or elsewhere (8 neighbouring cells). A rotation point is a cell that has 8 neighbouring cells. Example rotation points on a grid are marked with R below, and their neighbouring cells are marked with N :
|
||||
NNN.. ..... ..... .....
|
||||
NRN.. ..... NNN.. .NNN.
|
||||
NNN.. ..NNN NRN.. .NRN.
|
||||
..... ..NRN NNN.. .NNN.
|
||||
..... ..NNN ..... .....
|
||||
To untangle the hidden message, you need to rotate the 8 cells surrounding each rotation point to the left or right according to the message key. Start from the top leftmost rotation point, continuing through all the rotation points to the right on the same row, then proceed to the following row, moving from left to right. Repeat this process until you reach the final rotation point on the bottom right. Note that the border cells are not rotation points, as they do not have 8 surrounding neighbouring cells.
|
||||
Below you can see the correct order for processing all 9 rotation points on the sample 5x5 grid:
|
||||
NNN.. .NNN. ..NNN ..... ..... ..... ..... ..... .....
|
||||
NRN.. .NRN. ..NRN NNN.. .NNN. ..NNN ..... ..... .....
|
||||
NNN.. .NNN. ..NNN NRN.. .NRN. ..NRN NNN.. .NNN. ..NNN
|
||||
..... ..... ..... NNN.. .NNN. ..NNN NRN.. .NRN. ..NRN
|
||||
..... ..... ..... ..... ..... ..... NNN.. .NNN. ..NNN
|
||||
There are 2 possible operations that can be performed on rotation points:
|
||||
R - rotate neighbouring cells by one item clockwise:
|
||||
ABC HAB
|
||||
HxD > GxC
|
||||
GFE FED
|
||||
|
||||
|
||||
L - rotate neighbouring cells by one item counterclockwise:
|
||||
ABC BCD
|
||||
HxD > AxE
|
||||
GFE HGF
|
||||
The message key contains a sequence of R and L operations that should be performed on all rotation points on the message grid. If the key is shorter than the number of operations required, you simply repeat the key as many times as necessary.
|
||||
The final message always starts after the > and ends before the < characters. These characters are always unique within the grid.
|
||||
You decide to practise decoding a sample message from the book (your notes), just for fun.
|
||||
Example based on the following notes:
|
||||
LR
|
||||
|
||||
>-IN-
|
||||
-----
|
||||
W---<
|
||||
The first line contains the message key: LR . You can repeat it as many times as needed, so in fact it looks like this: LRLRLRLRLR... . The rest of the input is separated by an empty line and represents the hidden message.
|
||||
To read the message, you need to perform the key operations sequence on the message grid. The sample grid is small, so there are only 3 rotation points. Below you can see the sequence of operations with the rotation points highlighted:
|
||||
|
||||
>-IN- -I-N- --I-- ----- -----
|
||||
----- >---- >W-N- >WIN< >WIN<
|
||||
W---< -W--< ----< ----- -----
|
||||
|
||||
start L R L end
|
||||
You can confirm that decoding is successful, because > and < are in the same line.
|
||||
In the example above the hidden message is WIN.
|
||||
What is the message hidden in the example you are analysing?
|
||||
|
||||
Part II
|
||||
|
||||
Of course, that was only an example showing the basic idea. The real messages had additional, misleading symbols which made the decoding process much more difficult. Additionally, processing the message according to the key only once was deemed insufficient, as it could be easily decoded by enemies.
|
||||
Standard messages assumed that the operations for the whole message needed to be repeated 100 times. Each time you start from the top left rotation point and from the beginning of the message key sequence.
|
||||
You find another riddle in the book (your notes), where the hidden message is the number of potions used by Sir Enigmatus Encriptus during the battle with the HTML (Hulking Tapestry Mighty Leviathan).
|
||||
Example based on the following notes:
|
||||
RRLL
|
||||
|
||||
A.VI..>...T
|
||||
.CC...<...O
|
||||
.....EIB.R.
|
||||
.DHB...YF..
|
||||
.....F..G..
|
||||
D.H........
|
||||
Below you can see all the rotation points highlighted for a single round of operations. You must visit them in order, from left to right and row by row, from top to bottom.
|
||||
|
||||
Result after 1 round of operations:
|
||||
.C...E.....
|
||||
..IB...YFB.
|
||||
.A..V...>TO
|
||||
.CH....I...
|
||||
.D.....FR..
|
||||
D.<.H..G...
|
||||
Results after 2, 3, 4, and 5 rounds:
|
||||
..C.V..F>.B
|
||||
A....B.I..Y
|
||||
.....E.F...
|
||||
.I<D.......
|
||||
.D...HG.T..
|
||||
C...H.OR... A....EB....
|
||||
...D..F..FI
|
||||
....C.G..BY
|
||||
V..D..O....
|
||||
.C..>HRH...
|
||||
I...<..T... ....C.....F
|
||||
...D.D.....
|
||||
.A...ERHB.I
|
||||
...C...G...
|
||||
VI...<THB..
|
||||
..F>..Y.O.. .....ED.B..
|
||||
A..C.D.G.H.
|
||||
......TH.F.
|
||||
C.FI..YR...
|
||||
..>V...<...
|
||||
......IB.O.
|
||||
Results after 97, 98, 99, and 100 rounds:
|
||||
....IECBV..
|
||||
..>......YF
|
||||
.A.....I.O.
|
||||
C.R.B.<.F..
|
||||
D..D.......
|
||||
..T.G...HH. ..........Y
|
||||
A...B.B.FI.
|
||||
...D.E..C.F
|
||||
I>T........
|
||||
C..DVG..OH.
|
||||
....R...<H. A..B.E.FC.I
|
||||
...........
|
||||
...D.....Y.
|
||||
....D...H..
|
||||
I..C.R.G.H.
|
||||
>.BVT.FO.<. ...........
|
||||
..B.D.F.H..
|
||||
.A.C.E.G.I.
|
||||
..B.D.F.H..
|
||||
.>VICTORY<.
|
||||
...........
|
||||
In the example above, the hidden message is VICTORY.
|
||||
Decode your message. What is the number of potions used by Sir Enigmatus Encriptus during the battle with the HTML?
|
||||
|
||||
Part III
|
||||
|
||||
The guard notices how adept you are with the arcane code and asks if you would like to try your hand at the official test. Every knight of the Order must pass it, so why not take this opportunity?
|
||||
The test involves deciphering another message written by Sir Enigmatus Encriptus from when he was on a reconnaissance mission and had to count the number of knights on Little Ending Island preparing legions for a huge invasion!
|
||||
The Order agreed to use 1048576000 rounds of operations instead of the regular 100 for such important messages!
|
||||
There is no way to do this by hand in a reasonable time; however, you have decoded the previous message, so you have something to experiment with.
|
||||
Decode your message. What was the number of knights on Little Ending Island?
|
217
2024/day19_encrypted_duck/src/lib.rs
Normal file
217
2024/day19_encrypted_duck/src/lib.rs
Normal file
|
@ -0,0 +1,217 @@
|
|||
use core::fmt::Display;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ParseError<'a> {
|
||||
InputMalformed(&'a str),
|
||||
InvalidOperation(char),
|
||||
MessageTooSmall,
|
||||
NonRectangular,
|
||||
StartMarkerCount,
|
||||
EndMarkerCount,
|
||||
}
|
||||
|
||||
impl Display for ParseError<'_> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::InputMalformed(e) => write!(f, "Unable to parse malformed input: {e}\nShould be the key, followed by an empty line, and the encrypted message."),
|
||||
Self::InvalidOperation(e) => write!(f, "Unable to parse {e} into an operation"),
|
||||
Self::MessageTooSmall => write!(f, "Message must be at least 3*3 characters"),
|
||||
Self::NonRectangular => write!(f, "All lines of the message must be of equal length"),
|
||||
Self::StartMarkerCount => write!(f, "There must be exactly one \'>\' in the message"),
|
||||
Self::EndMarkerCount => write!(f, "There must be exactly one \'<\' in the message"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
enum Operation{ Left, Right, }
|
||||
|
||||
struct Key {
|
||||
operations: Vec<Operation>
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for Key {
|
||||
type Error = ParseError<'a>;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
let operations = value.chars().map(|c| match c {
|
||||
'L' => Ok(Operation::Left),
|
||||
'R' => Ok(Operation::Right),
|
||||
e => Err(Self::Error::InvalidOperation(e)),
|
||||
}).collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(Self { operations })
|
||||
}
|
||||
}
|
||||
|
||||
struct Message {
|
||||
chars: Vec<Vec<char>>,
|
||||
width: usize,
|
||||
height: usize,
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a str> for Message {
|
||||
type Error = ParseError<'a>;
|
||||
|
||||
fn try_from(value: &'a str) -> Result<Self, Self::Error> {
|
||||
let chars: Vec<_> = value
|
||||
.lines()
|
||||
.map(|line| line.chars().collect::<Vec<_>>())
|
||||
.collect();
|
||||
|
||||
let height = chars.len();
|
||||
if height < 3 {
|
||||
return Err(Self::Error::MessageTooSmall);
|
||||
}
|
||||
let width = chars[0].len();
|
||||
if width < 3 {
|
||||
return Err(Self::Error::MessageTooSmall);
|
||||
}
|
||||
if chars.iter().any(|row| row.len() != width) {
|
||||
return Err(Self::Error::NonRectangular);
|
||||
}
|
||||
if chars.iter().map(|row| row.iter().filter(|c| **c == '>').count()).sum::<usize>() != 1 {
|
||||
return Err(Self::Error::StartMarkerCount);
|
||||
}
|
||||
if chars.iter().map(|row| row.iter().filter(|c| **c == '<').count()).sum::<usize>() != 1 {
|
||||
return Err(Self::Error::EndMarkerCount);
|
||||
}
|
||||
|
||||
Ok(Self { chars, width, height, })
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Message {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.chars
|
||||
.iter()
|
||||
.map(|row| row.iter().collect::<String>())
|
||||
.collect::<String>()
|
||||
.split(&['>', '<'][..])
|
||||
.nth(1)
|
||||
.unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl Message {
|
||||
fn permutation_cycles(&self, key: &Key) -> Vec<Vec<(usize, usize)>> {
|
||||
let mut grid = (0..self.height).map(|y|
|
||||
(0..self.width).map(|x| (y, x)).collect::<Vec<_>>()
|
||||
).collect::<Vec<_>>();
|
||||
(0..self.height-2).for_each(|y|
|
||||
(0..self.width-2).for_each(|x| {
|
||||
let step = y * (self.width-2) + x;
|
||||
rotate(&mut grid, x+1, y+1, key.operations[step % key.operations.len()]);
|
||||
}));
|
||||
let mut res: Vec<Vec<(usize, usize)>> = Vec::new();
|
||||
(0..self.height).for_each(|old_y|
|
||||
(0..self.width).for_each(|old_x| {
|
||||
let mut old = (old_y, old_x);
|
||||
loop {
|
||||
let new = grid
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find_map(|(y, row)| row
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_x, old_entry)| **old_entry == old)
|
||||
.map(|(x, _old_entry)| (y, x))
|
||||
).unwrap();
|
||||
if let Some(idx) = res.iter().position(|seq| seq.contains(&old)) {
|
||||
if !res[idx].contains(&new) {
|
||||
// assert!(res[idx].iter().position(|o| *o == old) == Some(res[idx].len()-1));
|
||||
res[idx].push(new);
|
||||
old = new;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
res.push(Vec::from([old, new]));
|
||||
old = new;
|
||||
}
|
||||
}
|
||||
}));
|
||||
res
|
||||
}
|
||||
|
||||
fn apply_permutation_cycles(&mut self, cycles: &[Vec<(usize, usize)>], count: usize) {
|
||||
let old = self.chars.clone();
|
||||
(0..self.height).for_each(|y|
|
||||
(0..self.width).for_each(|x| {
|
||||
let cycle = cycles.iter().find(|c| c.contains(&(y, x))).unwrap();
|
||||
let offset = cycle.iter().position(|ge| *ge == (y, x)).unwrap();
|
||||
let (new_y, new_x) = cycle[(count + offset) % cycle.len()];
|
||||
self.chars[new_y][new_x] = old[y][x];
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
fn rotate(grid: &mut [Vec<(usize, usize)>], x: usize, y: usize, direction: Operation) {
|
||||
let temp = grid[y-1][x-1];
|
||||
match direction {
|
||||
Operation::Left => {
|
||||
grid[y-1][x-1] = grid[y-1][x];
|
||||
grid[y-1][x] = grid[y-1][x+1];
|
||||
grid[y-1][x+1] = grid[y][x+1];
|
||||
grid[y][x+1] = grid[y+1][x+1];
|
||||
grid[y+1][x+1] = grid[y+1][x];
|
||||
grid[y+1][x] = grid[y+1][x-1];
|
||||
grid[y+1][x-1] = grid[y][x-1];
|
||||
grid[y][x-1] = temp;
|
||||
},
|
||||
Operation::Right => {
|
||||
grid[y-1][x-1] = grid[y][x-1];
|
||||
grid[y][x-1] = grid[y+1][x-1];
|
||||
grid[y+1][x-1] = grid[y+1][x];
|
||||
grid[y+1][x] = grid[y+1][x+1];
|
||||
grid[y+1][x+1] = grid[y][x+1];
|
||||
grid[y][x+1] = grid[y-1][x+1];
|
||||
grid[y-1][x+1] = grid[y-1][x];
|
||||
grid[y-1][x] = temp;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(input: &str, part: usize) -> Result<String, ParseError> {
|
||||
if let Some((key, message)) = input.split_once("\n\n") {
|
||||
let key = Key::try_from(key)?;
|
||||
let mut message = Message::try_from(message)?;
|
||||
let cycles = message.permutation_cycles(&key);
|
||||
match part {
|
||||
1 => message.apply_permutation_cycles(&cycles, 1),
|
||||
2 => message.apply_permutation_cycles(&cycles, 100),
|
||||
3 => message.apply_permutation_cycles(&cycles, 1048576000),
|
||||
_ => panic!("Illegal part number"),
|
||||
}
|
||||
Ok(message.to_string())
|
||||
} else {
|
||||
Err(ParseError::InputMalformed(input))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs::read_to_string;
|
||||
|
||||
fn read_file(name: &str) -> String {
|
||||
read_to_string(name).expect(&format!("Unable to read file: {name}")[..]).trim().to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sample() {
|
||||
let expected = ["WIN", "VICTORY"];
|
||||
for part in 1..=expected.len() {
|
||||
let sample_input = read_file(&format!("tests/sample{part}"));
|
||||
assert_eq!(run(&sample_input, part), Ok(expected[part-1].to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_challenge() {
|
||||
let expected = ["4877113951383767", "5529455775582299", "2423423664347316"];
|
||||
for part in 1..=expected.len() {
|
||||
let challenge_input = read_file(&format!("tests/challenge{part}"));
|
||||
assert_eq!(run(&challenge_input, part), Ok(expected[part-1].to_string()));
|
||||
}
|
||||
}
|
||||
}
|
5
2024/day19_encrypted_duck/tests/challenge1
Normal file
5
2024/day19_encrypted_duck/tests/challenge1
Normal file
|
@ -0,0 +1,5 @@
|
|||
LLRRLR
|
||||
|
||||
>+47++1+31++8+3+7<
|
||||
++++++++++++++++++
|
||||
8+++71+9++53+7++6+
|
23
2024/day19_encrypted_duck/tests/challenge2
Normal file
23
2024/day19_encrypted_duck/tests/challenge2
Normal file
|
@ -0,0 +1,23 @@
|
|||
LLRLLRLRLRLLRLRRLLRLRRRLLRLRLLLLLLRLRRRRRRRLLLRRLRLRRRLLLRLRRLLLLRLRRRLRRRLRRLLLRRLRRRRRLLLRLLRRLLLR
|
||||
|
||||
..+........+0..........M....OM.M.M.........MLK.W....
|
||||
+.........X.+........MK....0WM.NM.MKKMMMMMMXMMM.....
|
||||
.....2.M..+.W..0L.X...M...M.MM.MNM..M.MMMMMWMM......
|
||||
..........A...U.C+K..MMMKM..MM.MMM.MMMMMMM.NMMM.....
|
||||
..+.......;......<;.9.;ML...X.M0MM.MM.MMMMMMMMM.....
|
||||
..O.......X....DO9D.+KKOLM;.M.0MMM.MMMDM.MMMMM.0;..C
|
||||
N.9....................MM..MMNMMMMMMM;.MMM:...M.K;.X
|
||||
XX.CX.KDLC.......D...C..MM.MMM.M.M.MWOMDKM.KM.NMMO.K
|
||||
..+.W..MMM.WWN;.N+K+...DM.MMMMMMMWMMLXXMMMMMMWM.MN.O
|
||||
;....C.XOK..MMMMM...!...M.XMMXKMMKNWM..K.MMNCNMMMW.X
|
||||
..4..........Q..D+.+...WM.MOK.MWMMMMMMC.M.MM..X.MM.O
|
||||
..........2.........M...MMMMM.MMMM.;.M...N.M.M.MMM.;
|
||||
..+..+.D00.O.KXWX..KL...M..MMMMMMMMMOMMM.MOMK...MM..
|
||||
.........;..KO00K:.......M0M.MMMMKMMM0MM.M.M..MMMW..
|
||||
...............:.0X.0..KMXMMM..M.MM..M.MW;C.MW.MMK..
|
||||
..>..0....+X.....MWX....MMMM.;MM:WM.DM..MOMM:X0MWD..
|
||||
+.....MN......7K....MM..M.MM.OM0MMMMLKMWM.MM.X;MO...
|
||||
+...5.O++++.+++++..MW....MMMMMM.MMC..MW....M.MMO....
|
||||
....5...55N7.58.2CLWWM:MMMMM.0MMMMMK..MOMMXMMM.M....
|
||||
.....+.+++.+.+++5...OM.X.NMMMMN.O..:....N.M..W..M...
|
||||
....+...............NMM.WO.M.0....M.MW.W.M;M..OM....
|
79
2024/day19_encrypted_duck/tests/challenge3
Normal file
79
2024/day19_encrypted_duck/tests/challenge3
Normal file
|
@ -0,0 +1,79 @@
|
|||
LRLLRLRRRLLLRRRRLRRLRRLLLRRLRRLRLLLRRLRLLRRLLRRRRLRRRLRRLLLLRRRRLLRLLLRRLRLRRLRLRRRLLRLLLLRLRLLLLLRLRRRLLRLRLRLLLLLLRLRRLLRLRRRLL
|
||||
|
||||
EO..D..D..Y.EE..........E.O...V...........V..E...0.....DOE.C....D....................YDR.D...OVDCVR....RS.O....COYEO.Y.S.VD..E.DD..R.EE.S..YEEE..R.K..B...D...Y......OC....B..O...W...D..DC.ON...E..RV..
|
||||
...Y......YV..E........E.V.ESSE.....................XD.V..O.RCDE................R..W.NV.O.C..D.BCDE..Y...VO.:EL.SDBDDDSKEDEXE.OXBOO.S..O..CYOYEOY..................D.W.O...........YOCS.D..Y.EBEEO..V.O.
|
||||
..RDB..O....EV...K........COR....C...V....YSCE.OK.Y.DE.EE.E.....E.......W......VK.BD.O...D.YEDY.Y..:K.O.Y.C;XDDYVEOS.BRDDOEO.DDO.Y.C.D:BEKO.BYRR.ED...RE..O.N..D..B..BE....XDYB.C.DB.O...E.R.....Y...D..
|
||||
.....Y.......YY.........C..R.V....DD.......DV.R....CEVRY.....Y.O..................V...YD...DO.DOCW.WRE.BECOEEEO.OSEECYOCEVXCEEYWE.EOOYCB.CEYBODO...KOE....KE.E.C...OR....EVEEE.O.RERD.EEE.....Y.YO..S...
|
||||
.E.WE.LW....OE............YY.E...YSB.BC.EDD....VDE..O.......E.........R.N.....RE....O....C..E.Y.SE...ESDDEEOOEOESEVB....VE.EDSDBDD.E.DEEVRE..ES..V.D..DO.V:..R....DDYYNEEEB.D...DCDB.D............Y.....
|
||||
....EW.....R..............+R.E.Y..RR......E.EYY.....S..E.......O....V............L..OKYEED.KC...DEO.OD.BEREBRO..DBSB.RDR.ELORDR.BYEYCRO..YEDRO..C.Y.RYY...YR.....ERCO.D.EEEV.COO....E...R.......ED.O....
|
||||
..ODO..E..W.O....K.D.....++D.CRDVEEC.D.V.RE.....O.R.Y.D.E............VK.E......V..E..EY..DO.EY..DY.DSEDVOOYRSOR.RVEO.E.OV.BRDD.O.C...Y..RYVY.D...YDDOEE..BRV.E:.KCCE:..OBE..DEB..YYDLO.E.E..............
|
||||
..Y...0.EWE.B...............BE...BDEVE....Y.K.B.Y..E.V.R.E.D...Y...XRV..O..;.....YC.KCOE0S..E..DECOYC..O..EEB.YSYRSEEVCDYOSCEVE.DES.E..S.RXBYE...W...E..V;EBOV.EEEY.DYY...CK.Y.B.C..S.D.E...R...S.....Y.
|
||||
..S.......D.E......D..N.+....DEODOEEBE.EOR.W...OO.YYYSB.......B...R.O.RCX...VO...K.BOR.CDOCYD.D;YR.WO..R.YYYCVYXVYYRE.YNBRSVREDE.X..E..EEBCVEE.....BER.DYOBYYBEROYCD.WD.C.OOORY;RDOSVBCE.......D...V..CY
|
||||
V.W....X.O...E...........Y...VEVSYOCVS.O..O.0.Y...CDC......SVO....C.BY.0...Y;W....O...OE0D....WEOSBV.DRO.CDBYK.BEOSDORSCRCEDDCX.E.E.C...SVC.E.VVV.EERYEEVYYBRB....Y.DDO.C..BCO.V.E..EYO.....SY.....C..Y.
|
||||
.;E........YR.D.E..K...D..OORESYBCDEY.RDYY.C......ODO.C..R..D.R.....O.....COXDB..EYY.O...OYDY.EENRSNDEV.CYOCEDBV.WOESCO.D.ECELSER.E.D..SREVVRE....OYBE.EDDOBYE.YYE.OVCDDY.BOSDB..EDVBY.R..R....D....O..Y
|
||||
..D...0...S.....KRBO.EC0DYDS.VER.YEEEV..O.N.......YE.....C.YYDB...YOCX.D...0..D.....W.CDOO.....YYENC.RYYBSEB.CSYSYVBRCYD.YVY.EDED.....CYEEDEDOYRDCW.LDW.BVRREX.Y.OB.VOD.SW.C....B0S..EC...B.VDCS...O..V.
|
||||
.....Y.RO.C0WK..S.KYD.0...NE..RYBBVVB..YY......XV.........OOV.O.DEVYEEB..EVB.O......:YEO.C.OC.DD.BEO0EE..CO..SDDEEEDYEDCDOOE.0VEV.V..EOEORSEBYD..KREEX.ED.DY.RDB.DOVRDDB..OCV.DER.EKO......YY..D..EOEC.Y
|
||||
..Y...........6.DKCYDWX.E.BY..Y.KEYOD.OBW..Y.E..O.YS.....CRSSYOEBODV.EXE.RDR.EBE......O.X...OXRBOOE..DYDOR..V.EVVOSVYEED.RBC.BCREO..CYOWRSYBDSRV.ESE.;..V;O.YYV.YEBNOCR..X.KE.WES.C.......YVVSSS.K.E..O.
|
||||
...D...D....V.VBC...ECOYDOOE..WERREVVOE.K.O....V.CE.....D.SV.OEDCRY.CBE.BVEV.S.....Y.D.B......ROLSDSEEEC.N...ESRDYDOOSCDYOD.BSREYYC.R.RVOCOYEO.O.OYCB..E.....EY;ODSE.SVV..EEE.OEYC..E...OYBE..VORRVY.O.Y
|
||||
..ODC+..X...W....RKB....E0.Y.....DEE.R.W..KD....VSBCYD.B.DEY;BYVSCOD...R.O...EO.........RKE..YOVE.:R.DSEDO...DYSEEECEROVVOYOBDEDEDD...YRYDBDVCOOYSYO.C.EO.OOROYWSCE.BOB.YYDE...OE.......B.E.V.ED.CRY....
|
||||
CYE..E.O..KVY...DVR...YV.XEEK.BE.E.B.OVEXWD...RREOD.E.ORCVOERRESROY...E.OESW.D.....O...Y.DB....D.LNDDEVBVBE.BX.VCRYDEESERSBCEERVCSE.YBS..DVROS.RBDCEYRVE...E.DXEXD.YVESRE.ESD.OE....D..N:N.V...EEB.R....
|
||||
DVS.D..<....D....L...7......EO...S.E.W..:.RECVKEVYE.0E.EBY;ODYEEOSOC.E.EDCWYESB.......O.O..B...RWB..DYVSSEYYE.YCSYVEVEESDSROOYECEYE.K.YEY.DVEODCB..DDEEDEY.YC.W.EYSOOY..DODN.:B.....Y.......OVYE.B......
|
||||
YEY.......XO...BDKK.+.+...E.K.Y..YDRCEEY.Y.O.ECVDB....:YYDCEEECEDODWW.S....EYC.....C....0Y.Y...RESVSOLEDRE.SKDOOYEBOEVEEDCCDEO.EDVYEDOCD..VEOB.DRSYOESCEE.SYDLY.SK.:YY...C.EW............D.BCO.E.E......
|
||||
.VO.D.....C.+...D...6...V.V.YY...B.DE.Y.EE.YEDCDEE..EK.V..WRE.NEYSB.EC..DECXE.0.K.O...Y.......O.B.OD.SEDEERROBBCDCVSSEDDYBODCDDODESE.VEDBDOEDDCBOR.OYO.CDYVRCX;.DBEYO.D.C..V........L.....0.BY...C......
|
||||
..E............O...+.+...V0D.EDOE.YSVYEDKECY....BY.E.B.YKNODSSXYD.DOS..YV..:.Y....D...Y.OY........DSOCRERCEYYEODYDDVVDREYRVOBCSODREBDYSKXOVBVB.O:BDDEEEY..ORW...EOOCD....................VOD.D......DB..
|
||||
....E..O.E..Y...N..+4...C.C.EB.B..0BBO..OODB.OBESE+CE..Y.VCYS..OYOND.EYO.O.....O.RW...X..OYXXR..RYODEVEXDDSDYOORCEDYEVEEEEE.YROYERRCOSEOEOYB.Y.OBBYBOY...ORY.OY.BORED..YC........O.WC..0.EO..E..ES......
|
||||
.....S.Y.R....RY..+SOB.O.B.SOES2OK.EEY..D.RO.C..R.OO.O.OB:..E.YBC.N.EOEDV......Y.....L...O.K.E....DDY.YECCOOWSCYCBOOBCDOYEEDBDYBDR.LDDO.CYBVREYCKEDDDD..C.YB...BYBROEYD.Y.......V.CB.....YDO;S.RE....C..
|
||||
.........O..BEV..OE...O...R.SO.VE2.EDDEVE.EVOOCDDRRBKOO.WDOEEYSDV.CX..EDD.B.OCY.RY..R.DERB..EEEW...VVOC.DYSEDEDECEEEYBEDOREYRDR.RDWYE.YOEDVN:DDEEYO..C.O..ERWR..DYEVO.Y..........DOYY..E.Y..O.RY.D......
|
||||
..........EBVK..C.CEYO.EYS...CR.+.ROBR.YDXREDODERDCYC0DERE..DCEK...E..YYOVE.....Y.E.V.............K.C.ODCDYOYYBCDDYEDCOOSBEBYY.BEO0..SE.KONYVYS.VD.CDOC.DEBYOEB.REEOY.DR......Y.......EV.DV...YEE.......
|
||||
.........Y.KR..X.R3E..E.....DD.DOOEDOYDV.XSSSEYDBVDDCSD.VKEE0SOVVSCO.EDVES...KYEB...EOEOE.....Y...E.;.OSY;DEOKOOEOCEBEDCEOYVEOEOOYBBEVECDXVD.D.CRDDCY..EKB.O..Y.YRELD.E.........YDD.C..D....C.VOV.V.....
|
||||
..E...V..YLR.............R....:..XS.V.YO..VE.ECE.YOYO.N.DVOD.VREECBWDSB.D....;0...EWXBE.V....CVV...K...DO.OOOYDDECRYSDVEBEOYEE.ODC.OSRE.COEEE.O;....L...Y.RD.D..ORYCW....OD......XB..O.SYYC.V.EEE;E.....
|
||||
....OCR0...RWN......+V..+.Y.C.E..BEEDCDDOYCDO.YEDDVDESDYY:EOE.ODEY...VEE..........LWXEW.YRR.E.BV.O....YE..OEV0KCDDVVVVOOYOCEOYROB.BOYCB.O...YO.ESY...RWRY;.Y.:.REERW0OD.......:..E....X..E;EEE...EY.....
|
||||
..0.Y.......X.....1.Y..O.E....RE.DO...SXRN.BR..O.O.Y..OEOODE.EEODS.E...DE.SCY...V.EKYOBYC.OE.CEE.....S..EV.C.OOYCSDDDYEDEO.BDEDBOOYBCROYDSSVDOORD.:.O.B...Y...E.;.E.YCK.B.O...DYNEC..WEOEVO.EDBR.B......
|
||||
.W..Y0.D..V.C.....+.O.EE+...YY..VEYNEBOR.CYEDVE.OW.WYDO.EOYCVEEBBOSE...YO.NE........WVE.S.OKK.D..S....OR..BEE.VVODEY:SCESYEVSE;SORYRRYCVDE.Y.S.S.Y.R.YOE0S.E..XESSEYORC..;.....DBRO..O..E.YD....N.YOD...
|
||||
....O.B....D......E..........;....DR.BCE.DDED....B.E;.C.BDDOOCYRVBEO..Y...D.O....OYDRDO.DSDD.C.;E.E.DVEYDV..KYSOE...EVDSO..EESDSYVYYEYVODE.R..C.O.EOE.E.......BY.K.DC..YR.....RSEOO.DC.B..Y.E.X..B......
|
||||
..K.B..Y..V..........+..6.......O.D.E..;YDEBOY.SV..OED.VEO.YYEREEEED.....O.R.B.R..R.EE..E.C..R...Y...OO.....D.CD.VDSDEYDCOVEESEORCEC.YEDRO.D.....EYC.O.K.V..OO...V.SCE.........DRCX..........RY.....D...
|
||||
ECCDX.X.ESX...........E.....O.E.D;VW...BOOE.O.VOEYX+E....ORBBYR.SNCYO.Y.....YB.Y.EO.K.WV.O.S.E.......EO.....BSE...EOYRVVYBEEDDCRYOY.YOEYYEEV..SECECDE..O.R.R..YV.S.CO...Y.D.EWBYECR...RB....B..ONV.RES..
|
||||
.XW...EEE.X..........E.........DBB.OD.NEEEYDYODYEOEOY..EO..EYYDEDOBCC.DV.RCVYR.B...NE...K.Y..E.........EN.W.B.ECE..SODBRSEVOESO.VYBOCVVEYBBC...;.YO..Y.O.O...K..OS;.EV.EVO..W.O.E:.....Y....Y.DO.N..EX..
|
||||
...;..BE...........W..........E.W....Y.BCYCE..;BDSY+C....3S.EVEDBDOYOOV...E.O;.OV.R.VY.V...R.......C.X........DYSD.DOYSYVBYEEDEE...DOYVOYDEE..DDYCE......Y.D..:S.E..B.O.V.D:CYOB:D.....R.XO.....V.....EN
|
||||
...WWOE.....L........E...EYB..RVLCYCO.C..EEOY.VEDDE+EE..S.XE.EEE.0YECEOV.ERDDCD...Y.S..YKYE.B..E...C.C..;.D...OCYOVECY.DEDVDOOO..YBDEVDS...YYRR.ERDR.......LEOX.DVVESCODYO...;C.K.....E.DB.....D......VK
|
||||
.R......O...............O.....O.ONN..X...DK.DEWOYDE+B+4XO.BSO.ESDDEYORDERDCSOV.YC..N..YVC.ED.EE.....LOK.......DCSCYEDEE.Y.YSSED.ER.OE.E.YCC.....VNX.....DEW...E.OCVDV.DDDY..O..O;D.....YDYC..R..Y;.O.NC.
|
||||
..V..K0.V...E....YD.....OYD..............VRRR.Y.DYOWOBOSYKYYODE..0CEE.VD.OEEOEERC.E..W.O..N.D.........N.O.E....YEDCYOY..YSDDODYEYVR..XE..0..DVV.YE.......KOS.NE..YCYVCV.OR...C..O...V.......EE.DE....CC.
|
||||
0.....Y..........E.O...............R.O..D.D.OD..CODVYKX..KEKXDE.ODSDOSB..YSXESOEV..VDBD...EL.;........N;S......O.DDOSO.OC.BROO.BEDDRCDSKEOEDE...D..............WVOBYE.EOS.Y.E.YDYO..+.BYY.O..O......NN..
|
||||
........DY.....DOD.......................SDYB...SOORYE.RYDSEC0O..RDYS....X..RVDSE.S.B.BYE.....C....W.X..........SOOYDDECYC.E.S.OEOED.DER...ED..............C.VDO.DDOBODCES.....ES...+...E..W..ROVR..WO..
|
||||
EE.................E.......B...D........YE..S0EVDOEOCYEC.D+O..D.DEE.RO.0..DDCEDVOOK....S.......R.................EVOYBDY.VEVOD.RYCRVY.O.Y.E..;..............E.KR.;O.DEYYS..BS.BE.Y++...Y....L.B..Y.O....
|
||||
D.E...CYO.......................E.O.....R..DY.E.DSO..B...S.0SCE.....D.YK.....YORBER.0EY.C..R.O..E.;............VCYEYOVCEDD.OYEYE..EEDYO...D.BOW............Y.D.E.....B.EC.OV....V.+..E..........EEY...:.
|
||||
VEO.K..............X..RL..N....BO...X.....X.OODRCDEBX.V4K3EDE..+LDVSERSYDOYEBDYEEVR.........W....YE.............BDE.VNOD...SYSEYDOECDVB.ESE........S..............O.RDRWORD.B.....+++.OR...E....VBC.....
|
||||
B.NRV..................YSR.....E..E....D....O..EDOE....0.OW.E..2.YD...ERDOYNE..DCY.E.E.....OB.CD..................CYEODE..EEDE...EDEOSDYS.V...K.O.DEK0...B.DL.VV.YD..O.N.DESC..O....O.K...V....EVYR.X.D.
|
||||
ERYRV........E........EY...........E.V.S.....BEO.O.Y.S...BRO..YE.OYB..EYEYR.R.VOEYE..Y..YR.O....D.K....C..........D.OC.E.ERVBDOODDECYOR.S.....S.D.EE...S.O.V..E.ODO....V.EBC.C.........B......E...VDR..B
|
||||
EVERE.........E.V.....S..E..S.E...L....V........O.R.VV.W...BV....EE.E.DYV.D..EYDVO..YB.......Y................OY..OECW0ESEYREEBOOEYWBRV.EV.....EECKE...D.E.OSDK.CKYSY.YO.YODDB......E..B.......OCDO.EDRE
|
||||
V.Y.DV.......VE...........VEV.E..............:.D...E.RRD34..C...CEES.CVCOS...VE..S.C.S...BE.L.EOO............E....O.SYV..SROEYEOVOEYDYE.B.....DV..N....E.SS.S.Y.DEBCO.O.E...Y.O.............V.ODE.OKBLR.
|
||||
.K.OVY.O.....O..O..V.S...X....E..............R..N...EBV.+.O.C...X.O.VYCS...E.CYSCOOD.EV.E.V..........YO..O..CYO.....YYEE.ECYEBVBBESDCEC.YS.RV.O..E;ES.DCS.ROECS.YEOBD.D..O.E.CC....CB........V.ORD.0DY..
|
||||
....EB........L..RVY.E.....E...OL...O..........YRYX..E.D...V....R...SR:0R.SE.EC....YV.....S...DYW.O......O..........OO.OSEYOREEDVEOCDEOYY.......K.EDY.CY:S..VODB...B.E......E.......D.......C.R.S.EDV..D
|
||||
E.RCE..Y....D........E........D.....R.......CO.DE.VOEEE.S.E......X..O.EB.OYC....C.BCY.O.....RYE.EB.CYD..............OBSCEEYRSYYSESOEDSVRDDR.EE...DW...CEO...O..EO0;EBSO.Y.ESYV.S..E.....Y....E:.EOSEYEYE
|
||||
..Y.....Y.O.C.W...K...W.........O........O.....DECSV.S.ELC...W..V...YB.W.O..OOCVE.REODY....V....W.E................O.R.SVDEY.YYCEDOYCEBDYC.S.Y.....SW.DV....R.O...NY...NERDOR.Y....E.....DYDE...OOEER.VV
|
||||
.CBO........D.............E.K...............Y...E.SOEED..:S.......YO..KC..DYE..DYS.YECE...VRB.................S.....DDYED..Y:DBEODRECOE.DSD..Y........Y.....R.VYL;KYYCEVYEB.VR.R........YO...YVVBEVECEEE
|
||||
DECD.......................................O....D..E...W.........ONOYC.D......DBV.YDOC....................R.........D..YRRCOSODEYODODDRD....W......D0.........COEO.YYE.EY.EEX.O.V.R.....C..YDEY.EED.O..Y
|
||||
.YOE.............................S...E........VK..SDE.RDD..........SE.XS..BX.B.BOWDEV.RBB............E.....Y.V........OYSR.LDE.ECEERERB.EO.........O.K0....S..YD.YYOYYEKRCOV...BO.X.......O.CBVYYCSO....
|
||||
..C...................................E.D.....RD...EY........OO..Y.YDS.V..Y.OD.CRDDSENO....O.....E........;E.........E.EEEYCDYRV.OBEYY..EXO.D........ODYE...C.ODDBBYBD.S.DBSOYEYL.E....S..ORYO.BBOY.::..
|
||||
EE..........................R........DC.........O..B...YCOB...S.D..B..ER...DYCODDOOYE..OD.........V.Y.....K..R....:...EYE.DBDC...EDRE.....Y..........OD..R.SDE.BKYOOYOEOEDY..D.....Y.V.D....EROWBEDC.E..
|
||||
..D..........................EEYR....Y..C....C..E..E.........Y.CR.E....BOD..ODESEDEC.YOOVO.......OE...........B.V.......ECBEV...SEXY........K........OCDDOEYE.EOCYROEESBRSVB.OE..RB....D..EDOE.BO.......
|
||||
...................E........YE...........D.O.Y0.Y.SD..BEOO.Y...YKK.....ODYC.DESEEYE.EBDWDE.BV..E.O..Y....E...B..........S.ER.C.OODB.O...C..V..........Y.DOBYYVVE.EYRRBDYOOD.OCE....O.....EDC.VE:YEVC.E.Y
|
||||
..COB...............DOO.....R..OXEE.Y......O.O..EVSD.DB.R.CN......L.C.WDY.O.ESERESYERDSVOESX.........O.V.E...........W..VDLDB.BBREEYEE....DYN..O......B;.O..CRSEOOCEDDBY.YRXYRO..EBR....O.E..E.D.Y......
|
||||
WRY...V...Y........CS.....K...D.BDY.D...Y......DOS..D.VBECVDRV......B..YCO.ESEVEY.OEDYC.OYRYN..SE........O..............S.R0Y..VEBEOO.ODE.YY..V.........DODWCDEODYVDECROVB...D...OBDR....C.....OLO......
|
||||
VEO.R......O.Y.....D..R..........V.;O..X...B..E.Y....O.E...EEE....Y.S.D.O.ESEVESRBOOYDNBEBOEO.R.Y...........E..E..EVS.......VE.RREODEDDS.COXY.D..DW.B..YKVY.OXC.CBYBCEVR.0YYES.Y.S..V....SE....O...C....
|
||||
EDE.......YB...........E.XO......V.W.DEV.B...RYY........N.YR.K.........Y.YDY..DESEOR..COEO..E.K.Y..............E.............OVOB.EYDREBYERYBOO.......V.YODEBOEDV.CROOD..BSYEB.O.O.D......E....V.D.K..R.
|
||||
.VD.B.....V..R....V........V.....B.RS0R.BD.B...EE........O.V..Y.......YDO.YBODYCO.KY.OKYYOBV.........Y....................N.CD.Y.OYYOBSOREOO.VO...EB..DCEY.XYDD...DCDDDS.DDVEO.YYEX.....O.....S.......K.
|
||||
..E...........R.E.V.;.......ERE...BEEOBEOEED....D.........XWERC.C.....Y.YCER..ONK..0X..DEV.....N..............V0..O.O.Y.O.........ESRDYYEYSYE.YR.E.Y....CYYEYC.K.EYDE...OOEVEEYE.S..K....S.....BYDS.....
|
||||
....E..V.R..B...E.E........E.......EBE..EEYY..Y.......................B.E.D.OREL.....O.R......E....E..............X.KO.....R.E...BCYSYEODDVOREC..D.O..DOBD.CO.E.BOVBCVE..COYEC.B.....B..C.....CD........
|
||||
.....XEE.B...BD.....YO.....VYE.....BR;OECYEE..........D.....R...X..DLEE...SE.0V.....V.K........Y.X............C.B.>.+OX.B.......O.E.DYRYSORRCECC.....YYR.RR.EBOEOYNDVOBO.BRDEY.EE..RD.E.RB.YE.E..YEDE.C.
|
||||
...E...O.Y..ROS.................X..BR.VKSREBY.C...........KB....KVDW.E.O....0....................................B.YD........YEE.NYVODSOYCBBCDDV.O..X.Y..S.ERR..SEBVES.YBOVDSC.D..OB.VO.O.......O.RSB.E.
|
||||
....BV0...YSEY....BDD........X.....KEX.EDOSVO.R..DS......WR...WY.....Y.....N................YE.........Y........EE......0..E..E.OO...EBYVEBBYBEDS..REY.......DY.SEVSRDDYVDDDOD.E..YVNE..EOE.EE....YE..D.
|
||||
...EEO.D.OS.E.................V..EO.D.SYEDSXEDD..........D.D.....DX...B.................E0.......X......R.V.....VO.VEE..Y....YE.RC;BDDREDDRY.Y.SYO...ES.....B.EDVEVSSO.EEVOEEYDS.DY.B..EDE.Y.Y.....O....
|
||||
..YDYO...VEE....................X.DDOO.E..EESCS...O0.....V.O.WEDYD...Y...............W......E.S........KL.........E.E.R.Y.....Y.E.EO0E;CDEDOEDOYOO....V....K.DE0RCRYVDEOO..BEBYE...SY.Y.OSE..O.....S.Y..
|
||||
SOEYOE.D...EE.VR.........W....K.EE.RB.EBREVOY.OD.W.......CYE.E..YD..................D.X.V....N.V.R.....D..E....S....DO........V.SEOVCOS.EBEBEY.YBY..B.....R...0WYCEEVE.BOOOEDY.YR.YEE.............R.O...
|
||||
OEOYCBRB....R.0...........ENV......OYYE.CKEYE............V.WVO.O.......................K..YW..EEE..........S.S.V...............EBD.DVY..EVSOEYDCD....D.....EOY....BREEOWED.BODDD..ORESE.LBV.Y........DX.
|
||||
YDEEEBYD..Y.O.V...........:..CY..KR...OYOVEOYD............RV...C.DKE..............C....OWS...NE.C.....W........E.....C.Y........EYEEYD.OCEEC:R.ORSE.C.....EO..ECOODO.E.EEVCEEROYE..0....YC.D....O.EOY..E
|
||||
YVBRODEW....................C.....ELN..E.NDEV...........C..YRBDO........R................OYXYXW...B.W.D...........X.B.D.......RDYDEVVYYS.DDE.SE.C.Y.R..YO.V..R.LY.EO.REVECERVORBY.D..W......D.C.......B.
|
||||
ROSVVCOEE.B..................D.L...W..NOSNBO..........BV...YOB.O...Y..................E.KEV.K.........O..........K.D...N........O.ODDD.BYEDSES;..CB.Y.........C.DOY.L.RYERBCDXCOK:..:L.D.ORE........B.SO
|
||||
OYYOD.ERBK.......K.....0........K0LK.W.K:..N.......R.E.....DCY.O....B..................ESLX.YX......................R..........EVYO.RE.V.V...VDODEE.O.OOEE.......YV..OO.SEDOOEVY..E.................ODD.
|
||||
BYOB..DED.B........X............;........:.E........R..E....YED....D.E...................EEWN......................E.O.........R.CODY..DE..V.C....O.Y........C...C...Y....D.OOC...W........D........EBEE
|
5
2024/day19_encrypted_duck/tests/sample1
Normal file
5
2024/day19_encrypted_duck/tests/sample1
Normal file
|
@ -0,0 +1,5 @@
|
|||
LR
|
||||
|
||||
>-IN-
|
||||
-----
|
||||
W---<
|
8
2024/day19_encrypted_duck/tests/sample2
Normal file
8
2024/day19_encrypted_duck/tests/sample2
Normal file
|
@ -0,0 +1,8 @@
|
|||
RRLL
|
||||
|
||||
A.VI..>...T
|
||||
.CC...<...O
|
||||
.....EIB.R.
|
||||
.DHB...YF..
|
||||
.....F..G..
|
||||
D.H........
|
0
2024/day19_encrypted_duck/tests/sample3
Normal file
0
2024/day19_encrypted_duck/tests/sample3
Normal file
Loading…
Add table
Add a link
Reference in a new issue