diff --git a/2016/day-08/Cargo.toml b/2016/day-08/Cargo.toml new file mode 100644 index 0000000..eab4a70 --- /dev/null +++ b/2016/day-08/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day-08" +version = "0.1.0" +authors = ["Bert Peters "] + +[dependencies] diff --git a/2016/day-08/input.txt b/2016/day-08/input.txt new file mode 100644 index 0000000..6085312 --- /dev/null +++ b/2016/day-08/input.txt @@ -0,0 +1,162 @@ +rect 1x1 +rotate row y=0 by 6 +rect 1x1 +rotate row y=0 by 3 +rect 1x1 +rotate row y=0 by 5 +rect 1x1 +rotate row y=0 by 4 +rect 2x1 +rotate row y=0 by 5 +rect 2x1 +rotate row y=0 by 2 +rect 1x1 +rotate row y=0 by 5 +rect 4x1 +rotate row y=0 by 2 +rect 1x1 +rotate row y=0 by 3 +rect 1x1 +rotate row y=0 by 3 +rect 1x1 +rotate row y=0 by 2 +rect 1x1 +rotate row y=0 by 6 +rect 4x1 +rotate row y=0 by 4 +rotate column x=0 by 1 +rect 3x1 +rotate row y=0 by 6 +rotate column x=0 by 1 +rect 4x1 +rotate column x=10 by 1 +rotate row y=2 by 16 +rotate row y=0 by 8 +rotate column x=5 by 1 +rotate column x=0 by 1 +rect 7x1 +rotate column x=37 by 1 +rotate column x=21 by 2 +rotate column x=15 by 1 +rotate column x=11 by 2 +rotate row y=2 by 39 +rotate row y=0 by 36 +rotate column x=33 by 2 +rotate column x=32 by 1 +rotate column x=28 by 2 +rotate column x=27 by 1 +rotate column x=25 by 1 +rotate column x=22 by 1 +rotate column x=21 by 2 +rotate column x=20 by 3 +rotate column x=18 by 1 +rotate column x=15 by 2 +rotate column x=12 by 1 +rotate column x=10 by 1 +rotate column x=6 by 2 +rotate column x=5 by 1 +rotate column x=2 by 1 +rotate column x=0 by 1 +rect 35x1 +rotate column x=45 by 1 +rotate row y=1 by 28 +rotate column x=38 by 2 +rotate column x=33 by 1 +rotate column x=28 by 1 +rotate column x=23 by 1 +rotate column x=18 by 1 +rotate column x=13 by 2 +rotate column x=8 by 1 +rotate column x=3 by 1 +rotate row y=3 by 2 +rotate row y=2 by 2 +rotate row y=1 by 5 +rotate row y=0 by 1 +rect 1x5 +rotate column x=43 by 1 +rotate column x=31 by 1 +rotate row y=4 by 35 +rotate row y=3 by 20 +rotate row y=1 by 27 +rotate row y=0 by 20 +rotate column x=17 by 1 +rotate column x=15 by 1 +rotate column x=12 by 1 +rotate column x=11 by 2 +rotate column x=10 by 1 +rotate column x=8 by 1 +rotate column x=7 by 1 +rotate column x=5 by 1 +rotate column x=3 by 2 +rotate column x=2 by 1 +rotate column x=0 by 1 +rect 19x1 +rotate column x=20 by 3 +rotate column x=14 by 1 +rotate column x=9 by 1 +rotate row y=4 by 15 +rotate row y=3 by 13 +rotate row y=2 by 15 +rotate row y=1 by 18 +rotate row y=0 by 15 +rotate column x=13 by 1 +rotate column x=12 by 1 +rotate column x=11 by 3 +rotate column x=10 by 1 +rotate column x=8 by 1 +rotate column x=7 by 1 +rotate column x=6 by 1 +rotate column x=5 by 1 +rotate column x=3 by 2 +rotate column x=2 by 1 +rotate column x=1 by 1 +rotate column x=0 by 1 +rect 14x1 +rotate row y=3 by 47 +rotate column x=19 by 3 +rotate column x=9 by 3 +rotate column x=4 by 3 +rotate row y=5 by 5 +rotate row y=4 by 5 +rotate row y=3 by 8 +rotate row y=1 by 5 +rotate column x=3 by 2 +rotate column x=2 by 3 +rotate column x=1 by 2 +rotate column x=0 by 2 +rect 4x2 +rotate column x=35 by 5 +rotate column x=20 by 3 +rotate column x=10 by 5 +rotate column x=3 by 2 +rotate row y=5 by 20 +rotate row y=3 by 30 +rotate row y=2 by 45 +rotate row y=1 by 30 +rotate column x=48 by 5 +rotate column x=47 by 5 +rotate column x=46 by 3 +rotate column x=45 by 4 +rotate column x=43 by 5 +rotate column x=42 by 5 +rotate column x=41 by 5 +rotate column x=38 by 1 +rotate column x=37 by 5 +rotate column x=36 by 5 +rotate column x=35 by 1 +rotate column x=33 by 1 +rotate column x=32 by 5 +rotate column x=31 by 5 +rotate column x=28 by 5 +rotate column x=27 by 5 +rotate column x=26 by 5 +rotate column x=17 by 5 +rotate column x=16 by 5 +rotate column x=15 by 4 +rotate column x=13 by 1 +rotate column x=12 by 5 +rotate column x=11 by 5 +rotate column x=10 by 1 +rotate column x=8 by 1 +rotate column x=2 by 5 +rotate column x=1 by 5 diff --git a/2016/day-08/main b/2016/day-08/main new file mode 100755 index 0000000..c622e4c Binary files /dev/null and b/2016/day-08/main differ diff --git a/2016/day-08/src/main.rs b/2016/day-08/src/main.rs new file mode 100644 index 0000000..1c3c4d1 --- /dev/null +++ b/2016/day-08/src/main.rs @@ -0,0 +1,88 @@ +use std::env; +use std::io::prelude::*; +use std::io::BufReader; +use std::fs::File; + +fn is_splitpoint(c: char) -> bool +{ + match c { + ' ' => true, + 'x' => true, + 'y' => true, + '=' => true, + _ => false, + } +} + +const WIDTH: usize = 50; +const HEIGHT: usize = 6; + +fn main() { + let args: Vec = env::args().collect(); + let f = File::open(&args[1]).expect("Could not open file"); + let reader = BufReader::new(f); + + let mut lights = [[false; HEIGHT]; WIDTH]; + for line in reader.lines() { + let contents = line.unwrap(); + let parts: Vec<&str> = contents.split(|c| is_splitpoint(c)).collect(); + + match parts[0] { + "rect" => { + let width: usize = parts[1].parse().unwrap(); + let height: usize = parts[2].parse().unwrap(); + for x in 0..width { + for y in 0..height { + lights[x][y] = true; + } + } + }, + "rotate" => { + let index: usize = parts[4].parse().expect("Invalid index"); + let amount: usize = parts[7].parse().expect("Invalid row"); + match parts[1] { + "row" => { + let mut copy = [false; WIDTH]; + for x in 0..WIDTH { + copy[x] = lights[x][index]; + } + for x in 0..WIDTH { + lights[(x + amount) % WIDTH][index] = copy[x]; + } + }, + "column" => { + let mut copy = [false; HEIGHT]; + for y in 0..HEIGHT { + copy[y] = lights[index][y]; + } + for y in 0..HEIGHT { + lights[index][(y + amount) % HEIGHT] = copy[y]; + } + } + _ => panic!("{} is not a supported rotation", parts[1]), + } + }, + _ => panic!("{} is not a supported operation", parts[0]), + } + } + + let mut count = 0; + for y in 0..HEIGHT { + for x in 0..WIDTH { + let mut c = ' '; + if lights[x][y] { + count += 1; + c = '★'; + } + print!("{}", c); + + // spacing between letters + if x % 5 == 4 { + print!(" "); + } + } + println!(""); + } + + println!("{} lights active.", count); +}