This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use colored::Colorize; | |
use std::{ | |
collections::{HashMap, HashSet, VecDeque}, | |
ops::Add, | |
}; | |
// We'll use a point to track where each position is on the map. | |
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | |
struct Point { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ | |
cell::RefCell, | |
collections::{HashMap, HashSet, VecDeque}, | |
rc::Rc, | |
}; | |
// Point is used to track the start and end of a block. | |
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | |
struct Point { | |
x: usize, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ | |
collections::{HashMap, HashSet, VecDeque}, | |
ops::Add, | |
}; | |
// Standard point in the garden. | |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | |
struct Point { | |
x: i32, | |
y: i32, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::{HashMap, HashSet, VecDeque}; | |
#[derive(Debug, Eq, PartialEq, Clone, Copy)] | |
enum Pulse { | |
High, | |
Low, | |
} | |
// A communication is a pulse from one module to another. | |
#[derive(Debug, Eq, PartialEq, Clone)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use nom::{ | |
branch::alt, | |
bytes::complete::tag, | |
character::complete::{alpha1, digit1, one_of}, | |
combinator::map, | |
multi::separated_list1, | |
sequence::tuple, | |
IResult, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashSet; | |
use nom::{ | |
bytes::complete::tag, | |
character::complete::{alphanumeric1, digit1, one_of, space1}, | |
sequence::tuple, | |
IResult, | |
}; | |
#[derive(Debug)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::{BinaryHeap, HashMap}; | |
// We need to track the direction we're coming from to make sure we | |
// don't go further in one direction than we're allowed. | |
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] | |
enum Direction { | |
North, | |
South, | |
East, | |
West, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{ | |
collections::{HashSet, VecDeque}, | |
ops::Add, | |
}; | |
#[derive(Clone, Debug, Eq, Hash, PartialEq)] | |
enum Direction { | |
Up, | |
Down, | |
Left, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use nom::{ | |
branch::alt, | |
bytes::complete::tag, | |
character::complete::{alpha1, digit1}, | |
combinator::map, | |
multi::separated_list1, | |
sequence::preceded, | |
IResult, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{collections::HashSet, hash::Hasher}; | |
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | |
struct Grid { | |
grid: Vec<Vec<char>>, | |
} | |
impl Grid { | |
fn parse(input: &str) -> Self { | |
let grid = input |