1
0
Fork 0

starting day17 solution

main
Andrew Coleman 2019-01-16 22:25:09 -05:00
parent 6bd5db6251
commit 4834780347
5 changed files with 1601 additions and 0 deletions

4
2018/day17/Cargo.lock generated Normal file
View File

@ -0,0 +1,4 @@
[[package]]
name = "day17"
version = "0.1.0"

7
2018/day17/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "day17"
version = "0.1.0"
authors = ["Andrew Coleman <penguincoder@gmail.com>"]
edition = "2018"
[dependencies]

1527
2018/day17/input Normal file

File diff suppressed because it is too large Load Diff

55
2018/day17/src/main.rs Normal file
View File

@ -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));
}
}

8
2018/day17/test-input Normal file
View File

@ -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