Day 4 solution!
This commit is contained in:
parent
c170aee068
commit
b2dcf20a27
|
@ -0,0 +1,140 @@
|
|||
SAXMASMMMASAMMMMXXMMXMMMSSMMMXSAAXMSSMSSSSSSSSXSASXMSMMMSASXSXMASXMSSSMXSSMXSMSSXMXXSXMXAMXMASXASXMSAMSSSMMAAXAMMXXSAMMSXSSSSMSMMSMSAXSAMXMX
|
||||
MXXAAMAAMAMASXSSSMMSAMMSAMASMMSXSAMXAAMAAAAAAXSXAMMMAMAAXAMMAXXAXAAAXMAMMAMAMMAMXMAXSASXSAMXAXMSMAMMAAXSAMXSSXMMMAMMASAMXAAAXAAAXAAMAMXAMXAM
|
||||
XSXMASXMMXSAMXAAXMASASMMXXAMAXXAMXXSMMMMMMMMMMXMXMAMASASMMMAMMMMXMMMMSAMSAMAXMAMAMMXSAMXMMXMASXAMXMSMMMSMXMXAXSAMSXSAMASMMMMMSMSMMSMAMSXMASA
|
||||
SMAMASMAMAMASMMMMMASMMXAAMMSSMMMMMXAXXXAMAMASXAASXXSASAXAAASAAAMASAXMSXXSMMMMSASXSMAMXMAMXAMXMXMMAMXAAAMXSMMMXMAMMAMSSXMMMSMAMXXXAAMAAXASAMS
|
||||
XMAMAXXAMSSXSMSAXMXSXSMSMMXAXAXMASAMXMMMSMSASXMXSAMMMMXSMMMMSSXSXSASAMXMMMSMMMAMAAMXMMSXSAXXAMAXASASXMSSXXAAXMXMMMMMASXAXAAMSSXXMXSSXSMMMAXX
|
||||
SSXSXMMXSMMMSASAMSMSAXAAAXMXMSMSASAMAMAAAAMASXMASAMXASXAXAXMXMASAMXMASMSAAAAMMSMSMMAXAAAMMSSXMAMMMAXXAXAXMSMSSMXAMXMAMSAMSXSMMMXXAMXXMASXMMS
|
||||
XAAAAMSMMMAAMMMSMAAMMMSMSMMMMMAMXSMXAXMSSSMAMXMASAMXMAASXSSMAMXMASASXMASMSSSMAMMXXSSSSMSMXXASASXMMXMMXMMMXMAAASXMMSMAXMXXMMSASMXSAMXSAAXAAA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MMSSMSSMMSSSMSMSMMSAMXMSMSMMAASXSAMXMXXMAXXSMSMSMMXXSMSXXAMXMASASMSSSSSMMSSMXAXSS
|
|
@ -1,5 +1,9 @@
|
|||
use nom::{
|
||||
branch::alt, bytes::complete::{tag, take_while}, character::{complete::anychar, is_digit}, combinator::eof, multi::{many1, many_till}, Err, Finish, IResult
|
||||
branch::alt,
|
||||
bytes::complete::{tag, take_while},
|
||||
character::{complete::anychar, is_digit},
|
||||
multi::{many1, many_till},
|
||||
Finish, IResult,
|
||||
};
|
||||
use regex::Regex;
|
||||
|
||||
|
@ -119,10 +123,13 @@ fn match_mult(input: &str) -> IResult<&str, Operation> {
|
|||
let (rest, y) = take_while(|c| is_digit(c as u8))(rest)?;
|
||||
let (rest, _) = tag(")")(rest)?;
|
||||
|
||||
Ok((rest, Operation::Mult(Multiplication {
|
||||
Ok((
|
||||
rest,
|
||||
Operation::Mult(Multiplication {
|
||||
x: x.parse::<i32>().unwrap(),
|
||||
y: y.parse::<i32>().unwrap(),
|
||||
})))
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -0,0 +1,226 @@
|
|||
const INPUT: &'static str = include_str!("../data/day4.txt");
|
||||
|
||||
pub fn day4a() -> String {
|
||||
let grid = Grid::from(INPUT);
|
||||
format!("{}", find_xmas(&grid))
|
||||
}
|
||||
|
||||
pub fn day4b() -> String {
|
||||
let grid = Grid::from(INPUT);
|
||||
format!("{}", find_x_mas(&grid))
|
||||
}
|
||||
|
||||
struct Grid {
|
||||
width: usize,
|
||||
height: usize,
|
||||
data: Vec<char>,
|
||||
}
|
||||
|
||||
impl Grid {
|
||||
fn elem(&self, x: usize, y: usize) -> char {
|
||||
if y >= self.height || x >= self.width {
|
||||
panic!("out of range")
|
||||
}
|
||||
self.data[y * self.width + x]
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for Grid {
|
||||
fn from(input: &str) -> Self {
|
||||
let height = input.lines().count();
|
||||
|
||||
let first_row = input.lines().next().unwrap();
|
||||
let width = first_row.len();
|
||||
|
||||
let data = input.chars().filter(|c| *c != '\n').collect::<Vec<char>>();
|
||||
|
||||
Self {
|
||||
width,
|
||||
height,
|
||||
data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum Direction {
|
||||
East,
|
||||
SouthEast,
|
||||
South,
|
||||
SouthWest,
|
||||
West,
|
||||
NorthWest,
|
||||
North,
|
||||
NorthEast,
|
||||
}
|
||||
|
||||
fn find_xmas(grid: &Grid) -> usize {
|
||||
let mut acc = 0;
|
||||
for x in 0..grid.width {
|
||||
for y in 0..grid.height {
|
||||
if check_xmas(grid, x, y, Direction::East) {
|
||||
acc += 1;
|
||||
}
|
||||
if check_xmas(grid, x, y, Direction::SouthEast) {
|
||||
acc += 1;
|
||||
}
|
||||
if check_xmas(grid, x, y, Direction::South) {
|
||||
acc += 1;
|
||||
}
|
||||
if check_xmas(grid, x, y, Direction::SouthWest) {
|
||||
acc += 1;
|
||||
}
|
||||
if check_xmas(grid, x, y, Direction::West) {
|
||||
acc += 1;
|
||||
}
|
||||
if check_xmas(grid, x, y, Direction::NorthWest) {
|
||||
acc += 1;
|
||||
}
|
||||
if check_xmas(grid, x, y, Direction::North) {
|
||||
acc += 1;
|
||||
}
|
||||
if check_xmas(grid, x, y, Direction::NorthEast) {
|
||||
acc += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
acc
|
||||
}
|
||||
|
||||
fn check_xmas(grid: &Grid, x: usize, y: usize, direction: Direction) -> bool {
|
||||
let mut addr: Option<(usize, usize)> = Some((x, y));
|
||||
|
||||
for c in "XMAS".chars() {
|
||||
if let Some((cx, cy)) = addr {
|
||||
if grid.elem(cx, cy) == c {
|
||||
addr = move_pointer(grid, cx, cy, direction);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
fn find_x_mas(grid: &Grid) -> usize {
|
||||
let mut acc = 0;
|
||||
for x in 1..grid.width - 1 {
|
||||
for y in 1..grid.width - 1 {
|
||||
if check_x_mas(grid, x, y) {
|
||||
acc += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
acc
|
||||
}
|
||||
|
||||
fn check_x_mas(grid: &Grid, x: usize, y: usize) -> bool {
|
||||
if grid.elem(x, y) != 'A' {
|
||||
return false;
|
||||
}
|
||||
|
||||
let nw = move_pointer(&grid, x, y, Direction::NorthWest).map(|(cx, cy)| grid.elem(cx, cy));
|
||||
let ne = move_pointer(&grid, x, y, Direction::NorthEast).map(|(cx, cy)| grid.elem(cx, cy));
|
||||
let se = move_pointer(&grid, x, y, Direction::SouthEast).map(|(cx, cy)| grid.elem(cx, cy));
|
||||
let sw = move_pointer(&grid, x, y, Direction::SouthWest).map(|(cx, cy)| grid.elem(cx, cy));
|
||||
|
||||
match (nw, ne, se, sw) {
|
||||
(Some(nw), Some(ne), Some(se), Some(sw)) => {
|
||||
// M . M
|
||||
// . A .
|
||||
// S . S
|
||||
if nw == 'M' && se == 'S' && ne == 'M' && sw == 'S' {
|
||||
return true;
|
||||
};
|
||||
|
||||
// M . S
|
||||
// . A .
|
||||
// M . S
|
||||
if nw == 'M' && se == 'S' && sw == 'M' && ne == 'S' {
|
||||
return true;
|
||||
};
|
||||
|
||||
// S . S
|
||||
// . A .
|
||||
// M . M
|
||||
if sw == 'M' && ne == 'S' && se == 'M' && nw == 'S' {
|
||||
return true;
|
||||
};
|
||||
|
||||
// S . M
|
||||
// . A .
|
||||
// S . M
|
||||
if se == 'M' && nw == 'S' && ne == 'M' && sw == 'S' {
|
||||
return true;
|
||||
};
|
||||
|
||||
false
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn move_pointer(grid: &Grid, x: usize, y: usize, direction: Direction) -> Option<(usize, usize)> {
|
||||
match direction {
|
||||
Direction::East if x < grid.width - 1 => Some((x + 1, y)),
|
||||
Direction::SouthEast if x < grid.width - 1 && y < grid.height - 1 => Some((x + 1, y + 1)),
|
||||
Direction::South if y < grid.height - 1 => Some((x, y + 1)),
|
||||
Direction::SouthWest if x > 0 && y < grid.height - 1 => Some((x - 1, y + 1)),
|
||||
Direction::West if x > 0 => Some((x - 1, y)),
|
||||
Direction::NorthWest if x > 0 && y > 0 => Some((x - 1, y - 1)),
|
||||
Direction::North if y > 0 => Some((x, y - 1)),
|
||||
Direction::NorthEast if x < grid.width - 1 && y > 0 => Some((x + 1, y - 1)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
const TEST_INPUT: &'static str = "MMMSXXMASM
|
||||
MSAMXMSMSA
|
||||
AMXSXMAAMM
|
||||
MSAMASMSMX
|
||||
XMASAMXAMM
|
||||
XXAMMXXAMA
|
||||
SMSMSASXSS
|
||||
SAXAMASAAA
|
||||
MAMMMXMMMM
|
||||
MXMXAXMASX";
|
||||
|
||||
#[test]
|
||||
fn it_finds_xmas() {
|
||||
let grid = Grid::from(TEST_INPUT);
|
||||
assert_eq!(find_xmas(&grid), 18);
|
||||
|
||||
let grid = Grid::from(INPUT);
|
||||
assert_eq!(find_xmas(&grid), 2633);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_finds_x_mas() {
|
||||
let grid = Grid::from(TEST_INPUT);
|
||||
assert_eq!(find_x_mas(&grid), 9);
|
||||
|
||||
let grid = Grid::from(INPUT);
|
||||
assert_eq!(find_x_mas(&grid), 1936);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_parses_the_grid() {
|
||||
let grid = Grid::from(TEST_INPUT);
|
||||
assert_eq!(grid.width, 10);
|
||||
assert_eq!(grid.height, 10);
|
||||
assert_eq!(grid.elem(9, 0), 'M');
|
||||
assert_eq!(grid.elem(9, 1), 'A');
|
||||
assert_eq!(grid.elem(9, 2), 'M');
|
||||
assert_eq!(grid.elem(9, 3), 'X');
|
||||
assert_eq!(grid.elem(9, 9), 'X');
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
mod day1;
|
||||
mod day2;
|
||||
mod day3;
|
||||
mod day4;
|
||||
|
||||
fn main() {
|
||||
let day = std::env::args().skip(1).next();
|
||||
|
@ -12,6 +13,8 @@ fn main() {
|
|||
Some("2b") => day2::day2b(),
|
||||
Some("3a") => day3::day3a(),
|
||||
Some("3b") => day3::day3b(),
|
||||
Some("4a") => day4::day4a(),
|
||||
Some("4b") => day4::day4b(),
|
||||
_ => panic!("unrecognized day"),
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue