56 lines
1.7 KiB
Rust
56 lines
1.7 KiB
Rust
|
use std::collections::VecDeque;
|
||
|
use std::fs::File;
|
||
|
use std::io::{BufRead, BufReader};
|
||
|
use std::ops::Range;
|
||
|
|
||
|
const MapSize: usize = 1800;
|
||
|
type Map = [[char; MapSize]; MapSize];
|
||
|
|
||
|
fn find_range_in_line(line: &str) -> (Range<u16>, Range<u16>) {
|
||
|
let mut parts = line.split(", ");
|
||
|
let mut left_parts = parts.nth(0).unwrap().split("=");
|
||
|
let left_coord_type: &str = left_parts.nth(0).unwrap();
|
||
|
let left_number: u16 = left_parts.nth(0).unwrap().parse().unwrap();
|
||
|
let mut right_parts = parts.nth(0).unwrap().split("=");
|
||
|
let mut right_numbers = right_parts.nth(1).unwrap().split("..");
|
||
|
let right_number_1: u16 = right_numbers.nth(0).unwrap().parse().unwrap();
|
||
|
let right_number_2: u16 = right_numbers.nth(0).unwrap().parse().unwrap();
|
||
|
let left_range = Range { start: left_number, end: left_number + 1 };
|
||
|
let right_range = Range { start: right_number_1, end: right_number_2 + 1 };
|
||
|
if left_coord_type == "x" {
|
||
|
(left_range, right_range)
|
||
|
} else {
|
||
|
(right_range, left_range)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn build_map_from_file(filename: &str) -> Map {
|
||
|
let lines: Vec<String> = BufReader::new(File::open(filename).unwrap())
|
||
|
.lines()
|
||
|
.map(|line| line.unwrap())
|
||
|
.collect();
|
||
|
let mut min_y = MapSize;
|
||
|
let mut max_y = 0;
|
||
|
let mut m: Map = [[' '; MapSize]; MapSize];
|
||
|
m[500][0] = '+';
|
||
|
for line in lines.iter() {
|
||
|
let (x_range, y_range) = find_range_in_line(line.as_str());
|
||
|
}
|
||
|
m
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
}
|
||
|
|
||
|
#[cfg(test)]
|
||
|
mod tests {
|
||
|
use super::*;
|
||
|
#[test]
|
||
|
fn test_range_from_line() {
|
||
|
let line = "x=100, y=100..102";
|
||
|
let (x_range, y_range) = find_range_in_line(line);
|
||
|
assert_eq!(x_range, (100..101));
|
||
|
assert_eq!(y_range, (100..103));
|
||
|
}
|
||
|
}
|