Day 04
This commit is contained in:
parent
b714aa6da1
commit
97c4162f5b
4 changed files with 279 additions and 2 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -19,7 +19,7 @@ checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
|||
|
||||
[[package]]
|
||||
name = "advent-of-code-2024"
|
||||
version = "24.3.2"
|
||||
version = "24.4.2"
|
||||
dependencies = [
|
||||
"regex-lite",
|
||||
"reqwest",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
authors = ["Toby <toby@tobot.dev>"]
|
||||
name = "advent-of-code-2024"
|
||||
version = "24.3.2"
|
||||
version = "24.4.2"
|
||||
edition = "2021"
|
||||
default-run = "get_input"
|
||||
|
||||
|
@ -43,6 +43,10 @@ path = "day02/main.rs"
|
|||
name = "day03"
|
||||
path = "day03/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "day04"
|
||||
path = "day04/main.rs"
|
||||
|
||||
[dependencies]
|
||||
regex-lite = "0.1.6"
|
||||
reqwest = { version = "0.12.9", features = ["blocking"] }
|
||||
|
|
140
day04/input.txt
Normal file
140
day04/input.txt
Normal file
|
@ -0,0 +1,140 @@
|
|||
SASASMSSSMSMSMSMSSMSAMXMAMAMXSXXXMAMMXSAMXMXMXSMMMXXXSXXAXSMMMAMXAXSMSSXXMSASASMXSSMSMSXMMMAMMMXXSAMXSSMXAXSASMMMXMASAXSXMXMAMXAMXXMAXXAMAMX
|
||||
AASAXAAAAXXASASMXSAXAMXXSMSSMSAXSMSMMASAMAAXMAMAAAMMMMMSMXSAMXSSMSMXMAXMASXAXAMXAAXMAMXAMASAMAAMXMASAMAAMSMSASASMMMMAMSXSMASMMSMSMMASMMMSAMA
|
||||
MXMXMMMSMMMMMAMXAMXMSSSMAXAAXMAMAAAXMASASMSXMASMMXSAAAAAMAXAMAXAAXAAMXMAMXMSMSMMXMASMSMXSASAXXXSASXMASXMMXAMMMAMMAXMXMMAXXA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MAMMAMXAMAXASAMMXSAMSMMXMSSXSASMMAAMXMAMAAAMXMMMSMMAMSMSXMASXSASMMXSASMXMAXMAMXMASMSMSSSMXSASASXMAXXMXMXMASXSMAMAXMASAAMXMMMAMSMAX
|
||||
SSMSXSAAXXMASXSXSASMSASAMAAMAMMMSXXXAASAMXMSMMSSMMXSAMAXSAMXMMMXAXASAMAMXMAMAMMMAXMAMMAMAMMSAXXMMXXAXXMAMXMSSSMSXXAAXXXMASXMASMMMSSMXMSAASXM
|
||||
XXAAMMMMSMSASAXAMAAXMASAMMSSMMMAMAMMMMMAMXAMXAAAAAMMAMXXMASXMMSMXMASAMXMASMMMSSSSSMAMSASXSSMMMASASASMSMSMSAAAAAMMMMMSMMMASAMSXAXAAXMAAXSMSXM
|
||||
MMMMAAAXAMMASMMXMSMSAMXXXXAAASMAMXMASXSSMMSMMMSSMMMSAMSXSAMXAAAAASXSAMXSASAAXAAAAAXAMSAMAMXAMSXMASAMSXAAAMMMSMMMAAAXXMASXSMMASMMMSASMSMAXMMS
|
||||
XMMXSMSMMSMAMXXXXXMAMSAMXMSSMMSMSASMSXXAXAXXMAXXMSAMXXXXMASAMSMSAMXSXMAMXSXMMMSMSMMMMMAMAMSSMMMMAMAMAMSMXMXXMXMASMMSAMXAASAMXSXXXXMXAMMAMXSX
|
133
day04/main.rs
Normal file
133
day04/main.rs
Normal file
|
@ -0,0 +1,133 @@
|
|||
pub const INPUT: &str = include_str!("./input.txt");
|
||||
|
||||
type Input = &'static str;
|
||||
type Output = usize;
|
||||
|
||||
fn parse_input(input: &'static str) -> Input {
|
||||
input
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let input = parse_input(INPUT);
|
||||
println!("Part 1: {}", part_1(&input));
|
||||
println!("Part 2: {}", part_2(&input));
|
||||
}
|
||||
|
||||
fn part_1(input: &Input) -> Output {
|
||||
let horizontal = input.match_indices("XMAS").count();
|
||||
let horizontal_reverse = input.match_indices("SAMX").count();
|
||||
|
||||
let grid = input
|
||||
.lines()
|
||||
.map(str::chars)
|
||||
.map(Iterator::collect::<Vec<_>>)
|
||||
.collect::<Vec<_>>();
|
||||
let grid_size = grid.len();
|
||||
let mut vertical = 0;
|
||||
let mut vertical_reverse = 0;
|
||||
for i in 0..grid.len() {
|
||||
let column = grid
|
||||
.iter()
|
||||
.map(|line| line.iter().skip(i).next().unwrap())
|
||||
.collect::<String>();
|
||||
vertical += column.match_indices("XMAS").count();
|
||||
vertical_reverse += column.match_indices("SAMX").count();
|
||||
}
|
||||
let mut diagonal_nw_se = 0;
|
||||
let mut diagonal_ne_sw = 0;
|
||||
for y in 0..=(grid_size - "XMAS".len()) {
|
||||
for x in 0..=(grid_size - "XMAS".len()) {
|
||||
let chars = [
|
||||
grid[y + 0][x + 0],
|
||||
grid[y + 1][x + 1],
|
||||
grid[y + 2][x + 2],
|
||||
grid[y + 3][x + 3],
|
||||
];
|
||||
if chars == ['X', 'M', 'A', 'S'] || chars == ['S', 'A', 'M', 'X'] {
|
||||
diagonal_nw_se += 1;
|
||||
}
|
||||
let reverse_chars = [
|
||||
grid[y + 0][x + 3],
|
||||
grid[y + 1][x + 2],
|
||||
grid[y + 2][x + 1],
|
||||
grid[y + 3][x + 0],
|
||||
];
|
||||
if reverse_chars == ['X', 'M', 'A', 'S'] || reverse_chars == ['S', 'A', 'M', 'X'] {
|
||||
diagonal_ne_sw += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
horizontal + horizontal_reverse + vertical + vertical_reverse + diagonal_nw_se + diagonal_ne_sw
|
||||
}
|
||||
|
||||
fn part_2(input: &Input) -> Output {
|
||||
let grid = input
|
||||
.lines()
|
||||
.map(str::chars)
|
||||
.map(Iterator::collect::<Vec<_>>)
|
||||
.collect::<Vec<_>>();
|
||||
let grid_size = grid.len();
|
||||
|
||||
let mut count = 0;
|
||||
for y in 1..grid_size - 1 {
|
||||
for x in 1..grid_size - 1 {
|
||||
if grid[y][x] != 'A' {
|
||||
continue;
|
||||
}
|
||||
let chars = [
|
||||
grid[y - 1][x - 1],
|
||||
grid[y + 1][x + 1],
|
||||
grid[y - 1][x + 1],
|
||||
grid[y + 1][x - 1],
|
||||
];
|
||||
if matches!((chars[0], chars[1]), ('S', 'M') | ('M', 'S'))
|
||||
&& matches!((chars[2], chars[3]), ('S', 'M') | ('M', 'S'))
|
||||
{
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
count
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::parse_input;
|
||||
|
||||
const SAMPLE_INPUT: &str = r#"MMMSXXMASM
|
||||
MSAMXMSMSA
|
||||
AMXSXMAAMM
|
||||
MSAMASMSMX
|
||||
XMASAMXAMM
|
||||
XXAMMXXAMA
|
||||
SMSMSASXSS
|
||||
SAXAMASAAA
|
||||
MAMMMXMMMM
|
||||
MXMXAXMASX"#;
|
||||
|
||||
#[test]
|
||||
fn test_part_1_with_sample_solution() {
|
||||
let input = parse_input(SAMPLE_INPUT);
|
||||
assert_eq!(super::part_1(&input), 18);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_part_1_with_solution() {
|
||||
let input = parse_input(super::INPUT);
|
||||
assert_eq!(super::part_1(&input), 2562);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_part_2_with_sample_solution() {
|
||||
let input = parse_input(SAMPLE_INPUT);
|
||||
assert_eq!(super::part_2(&input), 9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_part_2_with_solution() {
|
||||
let input = parse_input(super::INPUT);
|
||||
assert_eq!(super::part_2(&input), 1902);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue