Day 17 stuff
This commit is contained in:
@@ -2,8 +2,9 @@ use itertools::Itertools;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::utils;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use Tile::*;
|
||||
fn horizontal(line: &str) -> Option<(i32, i32, i32)> {
|
||||
let regex = Regex::new(r"y=(?P<y>\d+), x=(?P<x1>\d+)..(?P<x2>\d+)").unwrap();
|
||||
regex.captures(line).map(|m| {
|
||||
@@ -27,36 +28,36 @@ fn vertical(line: &str) -> Option<(i32, i32, i32)> {
|
||||
}
|
||||
pub fn task1() {
|
||||
let input = utils::read_file("input/day17.txt");
|
||||
let clay_tiles: HashSet<Pos> = input.lines().fold(HashSet::new(), |mut tiles, line| {
|
||||
let clay_tiles: HashMap<Pos, Tile> = input.lines().fold(HashMap::new(), |mut tiles, line| {
|
||||
if let Some((x, y1, y2)) = vertical(line) {
|
||||
for y in y1..=y2 {
|
||||
tiles.insert(Pos(x, y));
|
||||
tiles.insert(Pos(x, y), Clay);
|
||||
}
|
||||
}
|
||||
if let Some((y, x1, x2)) = horizontal(line) {
|
||||
for x in x1..=x2 {
|
||||
tiles.insert(Pos(x, y));
|
||||
tiles.insert(Pos(x, y), Clay);
|
||||
}
|
||||
}
|
||||
tiles
|
||||
});
|
||||
let (x_min, x_max) = clay_tiles
|
||||
.iter()
|
||||
.keys()
|
||||
.map(|p| p.0)
|
||||
.minmax()
|
||||
.into_option()
|
||||
.unwrap();
|
||||
let (y_min, y_max) = clay_tiles
|
||||
.iter()
|
||||
.keys()
|
||||
.map(|p| p.1)
|
||||
.minmax()
|
||||
.into_option()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
dbg!(x_min);
|
||||
dbg!(x_max);
|
||||
dbg!(y_min);
|
||||
dbg!(y_max);
|
||||
enum Tile {
|
||||
Clay,
|
||||
Water,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Hash)]
|
||||
|
||||
Reference in New Issue
Block a user