starting day17 solution
parent
6bd5db6251
commit
4834780347
|
@ -0,0 +1,4 @@
|
||||||
|
[[package]]
|
||||||
|
name = "day17"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
[package]
|
||||||
|
name = "day17"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Andrew Coleman <penguincoder@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,55 @@
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
x=495, y=2..7
|
||||||
|
y=7, x=495..501
|
||||||
|
x=501, y=3..7
|
||||||
|
x=498, y=2..4
|
||||||
|
x=506, y=1..2
|
||||||
|
x=498, y=10..13
|
||||||
|
x=504, y=10..13
|
||||||
|
y=13, x=498..504
|
Loading…
Reference in New Issue