diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 20:22:56 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2022-04-19 20:23:15 +0200 |
commit | 174772b5b8d9f5bf5e3c8e8152adfd89f0e83f6b (patch) | |
tree | a003b748ee939b30a2bcd3caf2378228baa304c1 /aoc8 | |
parent | fd75b3fb95ad049b0025cb8fc0b3459b8f872d61 (diff) |
Refile for merging repos
Diffstat (limited to 'aoc8')
-rw-r--r-- | aoc8/Cargo.lock | 98 | ||||
-rw-r--r-- | aoc8/Cargo.toml | 7 | ||||
-rw-r--r-- | aoc8/input.txt | 194 | ||||
-rw-r--r-- | aoc8/src/main.rs | 117 |
4 files changed, 0 insertions, 416 deletions
diff --git a/aoc8/Cargo.lock b/aoc8/Cargo.lock deleted file mode 100644 index dd33856..0000000 --- a/aoc8/Cargo.lock +++ /dev/null @@ -1,98 +0,0 @@ -[root] -name = "aoc8" -version = "0.1.0" -dependencies = [ - "regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "aho-corasick" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libc" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "memchr" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex" -version = "0.1.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "thread-id" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread_local" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "utf8-ranges" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "a51822fc847e7a8101514d1d44e354ba2ffa7d4c194dcab48870740e327cac70" -"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" -"checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" -"checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" -"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" -"checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" -"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/aoc8/Cargo.toml b/aoc8/Cargo.toml deleted file mode 100644 index c49deb6..0000000 --- a/aoc8/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "aoc8" -version = "0.1.0" -authors = ["Justin Worthe <justin.worthe@entelect.co.za>"] - -[dependencies] -regex = "0.1"
\ No newline at end of file diff --git a/aoc8/input.txt b/aoc8/input.txt deleted file mode 100644 index d827762..0000000 --- a/aoc8/input.txt +++ /dev/null @@ -1,194 +0,0 @@ -rect 1x1 -rotate row y=0 by 7 -rect 1x1 -rotate row y=0 by 5 -rect 1x1 -rotate row y=0 by 5 -rect 1x1 -rotate row y=0 by 2 -rect 1x1 -rotate row y=0 by 3 -rect 1x1 -rotate row y=0 by 5 -rect 1x1 -rotate row y=0 by 3 -rect 1x1 -rotate row y=0 by 2 -rect 1x1 -rotate row y=0 by 3 -rect 2x1 -rotate row y=0 by 7 -rect 6x1 -rotate row y=0 by 3 -rect 2x1 -rotate row y=0 by 2 -rect 1x2 -rotate row y=1 by 10 -rotate row y=0 by 3 -rotate column x=0 by 1 -rect 2x1 -rotate column x=20 by 1 -rotate column x=15 by 1 -rotate column x=5 by 1 -rotate row y=1 by 5 -rotate row y=0 by 2 -rect 1x2 -rotate row y=0 by 5 -rotate column x=0 by 1 -rect 4x1 -rotate row y=2 by 15 -rotate row y=0 by 5 -rotate column x=0 by 1 -rect 4x1 -rotate row y=2 by 5 -rotate row y=0 by 5 -rotate column x=0 by 1 -rect 4x1 -rotate row y=2 by 10 -rotate row y=0 by 10 -rotate column x=8 by 1 -rotate column x=5 by 1 -rotate column x=0 by 1 -rect 9x1 -rotate column x=27 by 1 -rotate row y=0 by 5 -rotate column x=0 by 1 -rect 4x1 -rotate column x=42 by 1 -rotate column x=40 by 1 -rotate column x=22 by 1 -rotate column x=17 by 1 -rotate column x=12 by 1 -rotate column x=7 by 1 -rotate column x=2 by 1 -rotate row y=3 by 10 -rotate row y=2 by 5 -rotate row y=1 by 3 -rotate row y=0 by 10 -rect 1x4 -rotate column x=37 by 2 -rotate row y=3 by 18 -rotate row y=2 by 30 -rotate row y=1 by 7 -rotate row y=0 by 2 -rotate column x=13 by 3 -rotate column x=12 by 1 -rotate column x=10 by 1 -rotate column x=7 by 1 -rotate column x=6 by 3 -rotate column x=5 by 1 -rotate column x=3 by 3 -rotate column x=2 by 1 -rotate column x=0 by 1 -rect 14x1 -rotate column x=38 by 3 -rotate row y=3 by 12 -rotate row y=2 by 10 -rotate row y=0 by 10 -rotate column x=7 by 1 -rotate column x=5 by 1 -rotate column x=2 by 1 -rotate column x=0 by 1 -rect 9x1 -rotate row y=4 by 20 -rotate row y=3 by 25 -rotate row y=2 by 10 -rotate row y=0 by 15 -rotate column x=12 by 1 -rotate column x=10 by 1 -rotate column x=8 by 3 -rotate column x=7 by 1 -rotate column x=5 by 1 -rotate column x=3 by 3 -rotate column x=2 by 1 -rotate column x=0 by 1 -rect 14x1 -rotate column x=34 by 1 -rotate row y=1 by 45 -rotate column x=47 by 1 -rotate column x=42 by 1 -rotate column x=19 by 1 -rotate column x=9 by 2 -rotate row y=4 by 7 -rotate row y=3 by 20 -rotate row y=0 by 7 -rotate column x=5 by 1 -rotate column x=3 by 1 -rotate column x=2 by 1 -rotate column x=0 by 1 -rect 6x1 -rotate row y=4 by 8 -rotate row y=3 by 5 -rotate row y=1 by 5 -rotate column x=5 by 1 -rotate column x=4 by 1 -rotate column x=3 by 2 -rotate column x=2 by 1 -rotate column x=1 by 3 -rotate column x=0 by 1 -rect 6x1 -rotate column x=36 by 3 -rotate column x=25 by 3 -rotate column x=18 by 3 -rotate column x=11 by 3 -rotate column x=3 by 4 -rotate row y=4 by 5 -rotate row y=3 by 5 -rotate row y=2 by 8 -rotate row y=1 by 8 -rotate row y=0 by 3 -rotate column x=3 by 4 -rotate column x=0 by 4 -rect 4x4 -rotate row y=4 by 10 -rotate row y=3 by 20 -rotate row y=1 by 10 -rotate row y=0 by 10 -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 1 -rotate column x=2 by 1 -rotate column x=1 by 1 -rotate column x=0 by 1 -rect 9x1 -rotate row y=0 by 40 -rotate column x=44 by 1 -rotate column x=35 by 5 -rotate column x=18 by 5 -rotate column x=15 by 3 -rotate column x=10 by 5 -rotate row y=5 by 15 -rotate row y=4 by 10 -rotate row y=3 by 40 -rotate row y=2 by 20 -rotate row y=1 by 45 -rotate row y=0 by 35 -rotate column x=48 by 1 -rotate column x=47 by 5 -rotate column x=46 by 5 -rotate column x=45 by 1 -rotate column x=43 by 1 -rotate column x=40 by 1 -rotate column x=38 by 2 -rotate column x=37 by 3 -rotate column x=36 by 2 -rotate column x=32 by 2 -rotate column x=31 by 2 -rotate column x=28 by 1 -rotate column x=23 by 3 -rotate column x=22 by 3 -rotate column x=21 by 5 -rotate column x=20 by 1 -rotate column x=18 by 1 -rotate column x=17 by 3 -rotate column x=13 by 1 -rotate column x=10 by 1 -rotate column x=8 by 1 -rotate column x=7 by 5 -rotate column x=6 by 5 -rotate column x=5 by 1 -rotate column x=3 by 5 -rotate column x=2 by 5 -rotate column x=1 by 5 diff --git a/aoc8/src/main.rs b/aoc8/src/main.rs deleted file mode 100644 index cb783ae..0000000 --- a/aoc8/src/main.rs +++ /dev/null @@ -1,117 +0,0 @@ -extern crate regex; -use regex::Regex; - -use std::io::BufReader; -use std::io::prelude::*; -use std::fs::File; - - -struct Screen { - data: [[bool; 6]; 50] -} - -impl Screen { - fn new() -> Screen { - Screen { - data: [[false; 6]; 50] - } - } - - fn rect(&mut self, a: usize, b: usize) { - for x in 0..a { - for y in 0..b { - self.data[x][y] = true; - } - } - } - - fn rotate_row(&mut self, y: usize, b: usize) { - let mut row_copy = [false; 50]; - for x in 0..50 { - row_copy[x] = self.data[x][y]; - } - for x in 0..50 { - self.data[x][y] = row_copy[(x+50-b)%50]; - } - } - - fn rotate_col(&mut self, x: usize, b: usize) { - let mut col_copy = [false; 6]; - for y in 0..6 { - col_copy[y] = self.data[x][y]; - } - for y in 0..6 { - self.data[x][y] = col_copy[(y+6-b)%6]; - } - } - - fn print(&self) { - for y in 0..6 { - for x in 0..50 { - print!("{}", if self.data[x][y] {'#'} else {'.'}); - } - println!(""); - } - } - - fn count_on(&self) -> u32 { - let mut count = 0; - for y in 0..6 { - for x in 0..50 { - if self.data[x][y] { - count += 1; - } - } - } - count - } -} - - -fn main() { - let lines = read_file(); - let mut screen = Screen::new(); - for line in lines { - if line.starts_with("rect") { - //rect 3x4 - let re = Regex::new(r"rect (\d+)x(\d+)").unwrap(); - let cap = re.captures(line.as_ref()).unwrap(); - println!("{} parsed as RECT. A={}, B={}", - line, - cap.at(1).unwrap_or(""), cap.at(2).unwrap_or("")); - screen.rect(cap.at(1).unwrap().parse().unwrap(), cap.at(2).unwrap().parse().unwrap()); - - } - else if line.starts_with("rotate row") { - //rotate row y=0 by 4 - let re = Regex::new(r"rotate row y=(\d+) by (\d+)").unwrap(); - let cap = re.captures(line.as_ref()).unwrap(); - println!("{} parsed as ROTATE ROW. A={}, B={}", - line, - cap.at(1).unwrap_or(""), cap.at(2).unwrap_or("")); - screen.rotate_row(cap.at(1).unwrap().parse().unwrap(), cap.at(2).unwrap().parse().unwrap()); - } - else if line.starts_with("rotate column") { - //rotate column x=1 by 1 - let re = Regex::new(r"rotate column x=(\d+) by (\d+)").unwrap(); - let cap = re.captures(line.as_ref()).unwrap(); - println!("{} parsed as ROTATE COLUMN. A={}, B={}", - line, - cap.at(1).unwrap_or(""), cap.at(2).unwrap_or("")); - screen.rotate_col(cap.at(1).unwrap().parse().unwrap(), cap.at(2).unwrap().parse().unwrap()); - - } - - screen.print(); - } - - println!("On: {}", screen.count_on()); -} - -fn read_file() -> Vec<String> { - let file = BufReader::new(File::open("input.txt").unwrap()); - file.lines() - .map(|line| line.unwrap().trim().to_string()) - .filter(|line| line.len() > 0) - .collect() -} |