extern crate advent_of_code_2018; use advent_of_code_2018::*; use std::str::FromStr; use std::error::Error; use std::path::PathBuf; use std::i32; // cargo watch -cs "cargo run --release --bin day_10" #[derive(Debug, Clone)] struct Star { x: i32, y: i32, dx: i32, dy: i32 } impl FromStr for Star { type Err = Box; fn from_str(s: &str) -> Result { let split = s .split(|c: char| c != '-' && !c.is_numeric()) .filter(|s| !s.is_empty()) .map(|s| s.parse()) .collect::, _>>()?; Ok(Star { x: split[0], y: split[1], dx: split[2], dy: split[3] }) } } fn main() -> Result<(), Box> { let input = read_file(&PathBuf::from("inputs/10.txt"))?; let mut stars = input.iter().map(|line| line.parse::().unwrap()).collect::>(); //debug!(input); //debug!(stars); let screen_width = 80; let screen_height = 80; for seconds in 0..1000000 { let min_x = stars.iter().map(|s| s.x).min().unwrap(); let max_x = stars.iter().map(|s| s.x).max().unwrap(); let min_y = stars.iter().map(|s| s.y).min().unwrap(); let max_y = stars.iter().map(|s| s.y).max().unwrap(); if max_x - min_x < screen_width && max_y - min_y < screen_height { debug!(seconds); for y in min_y..max_y+1 { for x in min_x..max_x+1 { let star_at_point = stars.iter().any(|s| s.x == x && s.y == y); if star_at_point { print!("#"); } else { print!(" "); } } println!(); } println!(); println!(); } for star in &mut stars { star.x += star.dx; star.y += star.dy; } } Ok(()) }