Commit 930f839c authored by Marcel Behrmann's avatar Marcel Behrmann

day(20): start solving

parent a0ce118e
mod utils;
mod intvm;
mod map;
use std::fs;
use std::collections::HashMap;
use map::Pos;
const INPUT_FILE: &str = "input.txt";
type Map = HashMap<Pos, char>;
type JumpTable = HashMap<Pos, char>;
fn main() {
let input = fs::read_to_string(INPUT_FILE).expect("Error reading input");
let input = input.lines();
......@@ -15,10 +22,77 @@ fn main() {
#[allow(unused_variables)]
fn part_01(input: Vec<&str>) {
println!("Result of Part 1");
let (map, dimensions) = build_map(input);
println!("Map dimensions: {:?}", dimensions);
let ( start, goal, network ) = analyze_network(&map, &dimensions);
println!("Found start at: {:?}", start);
println!("Found goal at: {:?}", goal);
}
fn build_map(input: Vec<&str>) -> (Map, (i32, i32)) {
let mut map: Map = Map::new();
let mut y = 0;
let mut x = 0;
let mut dimensions: (i32, i32) = (
0,
input.len() as i32,
);
// Save map to our dict
for line in input {
for c in line.chars() {
map.insert(Pos{x, y}, c);
x += 1;
if x > dimensions.0 {
dimensions.0 = x - 1;
}
}
y += 1;
x = 0;
}
(map, dimensions)
}
fn analyze_network(map: &Map, dimensions: &(i32, i32)) -> (Pos, Pos, JumpTable) {
let table: JumpTable = JumpTable::new();
let start = Pos{x: 0, y: 0};
let goal = Pos{x: 0, y: 0};
let neighbours = vec![
Pos{x: 0, y: -1},
Pos{x: 0, y: 1},
Pos{x: -1, y: 0},
Pos{x: 1, y: 0},
];
for x in 0..dimensions.0 {
for y in 0..dimensions.1 {
if let Some(c) = map.get(&Pos{x, y}) {
match c {
'A' ..= 'Z' => (),
_ => continue,
}
for neighbour in &neighbours {
}
panic!("Found a portal that does not make any sense");
}
}
}
(start, goal, table)
}
#[allow(unused_variables)]
fn part_02(input: Vec<&str>) {
println!("Result of Part 2");
}
\ No newline at end of file
}
use std::ops::{Add, AddAssign, Sub, SubAssign};
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Pos {
pub x: i32,
pub y: i32,
}
impl Add for Pos {
type Output = Pos;
fn add(self, other: Self) -> Self {
Self {
x: self.x + other.x,
y: self.y + other.y,
}
}
}
impl AddAssign for Pos {
fn add_assign(&mut self, other: Self) {
*self = Self {
x: self.x + other.x,
y: self.y + other.y,
};
}
}
impl Sub for Pos {
type Output = Pos;
fn sub(self, other: Self) -> Self {
Self {
x: self.x - other.x,
y: self.y - other.y,
}
}
}
impl SubAssign for Pos {
fn sub_assign(&mut self, other: Self) {
*self = Self {
x: self.x - other.x,
y: self.y - other.y,
};
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment