Skip to content

Commit

Permalink
[LIB] Fix swapped Grid method names
Browse files Browse the repository at this point in the history
  • Loading branch information
connorslade committed Dec 18, 2024
1 parent 6ab699b commit bbc6863
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions aoc_2021/src/day_15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ solution!("Chiton", 15);
type Point = Vector<usize, 2>;

fn part_a(input: &str) -> Answer {
let matrix = Grid::new(input, |chr| chr.to_digit(10).unwrap() as u8);
let matrix = Grid::parse(input, |chr| chr.to_digit(10).unwrap() as u8);
solve(matrix.size, |pos| matrix.get(pos).copied()).into()
}

fn part_b(input: &str) -> Answer {
let matrix = Grid::new(input, |chr| chr.to_digit(10).unwrap() as u8);
let matrix = Grid::parse(input, |chr| chr.to_digit(10).unwrap() as u8);
solve(matrix.size * 5, |pos| {
let (cx, cy) = (pos.x() / matrix.size.x(), pos.y() / matrix.size.y());
if cx > 4 || cy > 4 {
Expand Down
2 changes: 1 addition & 1 deletion aoc_2023/src/day_14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Dish {

fn parse(input: &str) -> Dish {
Dish {
tiles: Grid::new(input, identity),
tiles: Grid::parse(input, identity),
}
}

Expand Down
2 changes: 1 addition & 1 deletion aoc_2023/src/day_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn part_b(input: &str) -> Answer {
}

fn parse(input: &str) -> Grid<Tile> {
Grid::new(input, Tile::from_char)
Grid::parse(input, Tile::from_char)
}

#[derive(Debug, Clone, Copy, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion aoc_2023/src/day_17.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn part_b(input: &str) -> Answer {
}

fn parse(input: &str) -> Grid<u8> {
Grid::new(input, |c| c as u8 - b'0')
Grid::parse(input, |c| c as u8 - b'0')
}

fn pathfind(board: Grid<u8>, min_dist: u8, max_dist: u8) -> u32 {
Expand Down
2 changes: 1 addition & 1 deletion aoc_2023/src/day_21.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ enum Tile {
}

fn parse(input: &str) -> Grid<Tile> {
Grid::new(input, |x| match x {
Grid::parse(input, |x| match x {
'#' => Tile::Wall,
'.' => Tile::Garden,
'S' => Tile::Start,
Expand Down
2 changes: 1 addition & 1 deletion aoc_2023/src/day_23.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn solve_b(map: &Grid<char>) -> u32 {
}

fn parse(input: &str) -> Grid<char> {
Grid::new(input, identity)
Grid::parse(input, identity)
}

fn dir_matches(dir: Direction, chr: char) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions aoc_2024/src/day_04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use nd_vec::vector;
solution!("Ceres Search", 4);

fn part_a(input: &str) -> Answer {
let matrix = Grid::new(input, identity);
let matrix = Grid::parse(input, identity);
let mut count = 0;

for y in 0..matrix.size.y() {
Expand Down Expand Up @@ -44,7 +44,7 @@ const MAS_DIRECTIONS: [[Direction; 2]; 2] = [
];

fn part_b(input: &str) -> Answer {
let matrix = Grid::new(input, identity);
let matrix = Grid::parse(input, identity);
let mut count = 0;

for y in 0..matrix.size.y() {
Expand Down
2 changes: 1 addition & 1 deletion aoc_2024/src/day_06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct Map {

impl Map {
fn new(input: &str) -> Self {
let map = Grid::new(input, |x| match x {
let map = Grid::parse(input, |x| match x {
'#' => Tile::Obstacle,
'^' => Tile::Start,
_ => Tile::None,
Expand Down
2 changes: 1 addition & 1 deletion aoc_2024/src/day_08.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ enum Tile {

impl AntennaMap {
fn parse(input: &str) -> Self {
let world = Grid::new(input, |x| match x {
let world = Grid::parse(input, |x| match x {
'a'..='z' | 'A'..='Z' | '0'..='9' => Tile::Emitter(x),
_ => Tile::Empty,
});
Expand Down
2 changes: 1 addition & 1 deletion aoc_2024/src/day_10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct Map {

impl Map {
fn parse(input: &str) -> Self {
let board = Grid::new(input, |x| x.to_digit(10).unwrap());
let board = Grid::parse(input, |x| x.to_digit(10).unwrap());
Self { board }
}

Expand Down
2 changes: 1 addition & 1 deletion aoc_2024/src/day_12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Garden {

impl Garden {
fn parse(input: &str) -> Self {
let matrix = Grid::new(input, identity);
let matrix = Grid::parse(input, identity);
Self {
matrix,
seen: HashSet::new(),
Expand Down
2 changes: 1 addition & 1 deletion aoc_2024/src/day_15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum Tile {
impl Problem {
fn parse(input: &str, part_b: bool) -> Self {
let (board, instructions) = input.split_once("\n\n").unwrap();
let mut board = Grid::new(board, |chr| match chr {
let mut board = Grid::parse(board, |chr| match chr {
'@' => Tile::Robot,
'#' => Tile::Wall,
'O' => Tile::Box,
Expand Down
4 changes: 2 additions & 2 deletions aoc_2024/src/day_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct Item {

impl Maze {
fn parse(input: &str) -> Self {
let map = Grid::new(input, |c| match c {
let map = Grid::parse(input, |c| match c {
'.' => Tile::Empty,
'#' => Tile::Wall,
'S' => Tile::Start,
Expand All @@ -64,7 +64,7 @@ impl Maze {
fn foreword(&self) -> (Grid<[u32; 4]>, u32) {
let mut queue = BinaryHeap::new();
let mut seen = HashSet::new();
let mut costs = Grid::parse(self.map.size, [u32::MAX; 4]);
let mut costs = Grid::new(self.map.size, [u32::MAX; 4]);

queue.push(Item::new(self.start, Direction::Right, 0));

Expand Down
2 changes: 1 addition & 1 deletion aoc_2024/src/day_18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Map {
})
.collect::<Vec<_>>();

let board = Grid::parse(size, false);
let board = Grid::new(size, false);

Self { falling, board }
}
Expand Down
4 changes: 2 additions & 2 deletions aoc_lib/src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Grid<T> {
}

impl<T> Grid<T> {
pub fn parse(size: Vec2<usize>, default: T) -> Self
pub fn new(size: Vec2<usize>, default: T) -> Self
where
T: Clone,
{
Expand All @@ -23,7 +23,7 @@ impl<T> Grid<T> {
}
}

pub fn new(input: &str, parse: fn(char) -> T) -> Self {
pub fn parse(input: &str, parse: fn(char) -> T) -> Self {
let mut data = Vec::with_capacity(input.len());
let mut size = vector!(0, 0);

Expand Down

0 comments on commit bbc6863

Please sign in to comment.