From 7a8d39f5cab57bb670b8932673a0a55032916771 Mon Sep 17 00:00:00 2001 From: Philippe Zwietering Date: Fri, 17 Dec 2021 16:17:45 +0100 Subject: [PATCH] Changed advent_of_code rust stuff to be good cargo packages instead --- advent_of_code/{ => d1}/1.txt | 0 advent_of_code/d1/Cargo.lock | 7 +++++ advent_of_code/d1/Cargo.toml | 8 ++++++ advent_of_code/{1.rs => d1/src/main.rs} | 0 advent_of_code/{ => d2}/2.txt | 0 advent_of_code/d2/Cargo.lock | 7 +++++ advent_of_code/d2/Cargo.toml | 8 ++++++ advent_of_code/{2.rs => d2/src/main.rs} | 0 advent_of_code/{ => d3}/3.txt | 0 advent_of_code/d3/Cargo.lock | 7 +++++ advent_of_code/d3/Cargo.toml | 8 ++++++ advent_of_code/{3.rs => d3/src/main.rs} | 0 advent_of_code/{ => d4}/4.txt | 0 advent_of_code/d4/Cargo.lock | 7 +++++ advent_of_code/d4/Cargo.toml | 8 ++++++ advent_of_code/{4.rs => d4/src/main.rs} | 36 +++++++++++++++---------- 16 files changed, 82 insertions(+), 14 deletions(-) rename advent_of_code/{ => d1}/1.txt (100%) create mode 100644 advent_of_code/d1/Cargo.lock create mode 100644 advent_of_code/d1/Cargo.toml rename advent_of_code/{1.rs => d1/src/main.rs} (100%) rename advent_of_code/{ => d2}/2.txt (100%) create mode 100644 advent_of_code/d2/Cargo.lock create mode 100644 advent_of_code/d2/Cargo.toml rename advent_of_code/{2.rs => d2/src/main.rs} (100%) rename advent_of_code/{ => d3}/3.txt (100%) create mode 100644 advent_of_code/d3/Cargo.lock create mode 100644 advent_of_code/d3/Cargo.toml rename advent_of_code/{3.rs => d3/src/main.rs} (100%) rename advent_of_code/{ => d4}/4.txt (100%) create mode 100644 advent_of_code/d4/Cargo.lock create mode 100644 advent_of_code/d4/Cargo.toml rename advent_of_code/{4.rs => d4/src/main.rs} (71%) diff --git a/advent_of_code/1.txt b/advent_of_code/d1/1.txt similarity index 100% rename from advent_of_code/1.txt rename to advent_of_code/d1/1.txt diff --git a/advent_of_code/d1/Cargo.lock b/advent_of_code/d1/Cargo.lock new file mode 100644 index 0000000..dda6202 --- /dev/null +++ b/advent_of_code/d1/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "d1" +version = "0.1.0" diff --git a/advent_of_code/d1/Cargo.toml b/advent_of_code/d1/Cargo.toml new file mode 100644 index 0000000..4fb6a1c --- /dev/null +++ b/advent_of_code/d1/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "d1" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/advent_of_code/1.rs b/advent_of_code/d1/src/main.rs similarity index 100% rename from advent_of_code/1.rs rename to advent_of_code/d1/src/main.rs diff --git a/advent_of_code/2.txt b/advent_of_code/d2/2.txt similarity index 100% rename from advent_of_code/2.txt rename to advent_of_code/d2/2.txt diff --git a/advent_of_code/d2/Cargo.lock b/advent_of_code/d2/Cargo.lock new file mode 100644 index 0000000..0a330d8 --- /dev/null +++ b/advent_of_code/d2/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "d2" +version = "0.1.0" diff --git a/advent_of_code/d2/Cargo.toml b/advent_of_code/d2/Cargo.toml new file mode 100644 index 0000000..d140e99 --- /dev/null +++ b/advent_of_code/d2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "d2" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/advent_of_code/2.rs b/advent_of_code/d2/src/main.rs similarity index 100% rename from advent_of_code/2.rs rename to advent_of_code/d2/src/main.rs diff --git a/advent_of_code/3.txt b/advent_of_code/d3/3.txt similarity index 100% rename from advent_of_code/3.txt rename to advent_of_code/d3/3.txt diff --git a/advent_of_code/d3/Cargo.lock b/advent_of_code/d3/Cargo.lock new file mode 100644 index 0000000..dc31ee7 --- /dev/null +++ b/advent_of_code/d3/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "d3" +version = "0.1.0" diff --git a/advent_of_code/d3/Cargo.toml b/advent_of_code/d3/Cargo.toml new file mode 100644 index 0000000..0ed60d4 --- /dev/null +++ b/advent_of_code/d3/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "d3" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/advent_of_code/3.rs b/advent_of_code/d3/src/main.rs similarity index 100% rename from advent_of_code/3.rs rename to advent_of_code/d3/src/main.rs diff --git a/advent_of_code/4.txt b/advent_of_code/d4/4.txt similarity index 100% rename from advent_of_code/4.txt rename to advent_of_code/d4/4.txt diff --git a/advent_of_code/d4/Cargo.lock b/advent_of_code/d4/Cargo.lock new file mode 100644 index 0000000..35783ca --- /dev/null +++ b/advent_of_code/d4/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "d4" +version = "0.1.0" diff --git a/advent_of_code/d4/Cargo.toml b/advent_of_code/d4/Cargo.toml new file mode 100644 index 0000000..d057ef5 --- /dev/null +++ b/advent_of_code/d4/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "d4" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/advent_of_code/4.rs b/advent_of_code/d4/src/main.rs similarity index 71% rename from advent_of_code/4.rs rename to advent_of_code/d4/src/main.rs index 35ff8b4..200927b 100644 --- a/advent_of_code/4.rs +++ b/advent_of_code/d4/src/main.rs @@ -14,13 +14,13 @@ use std::collections::HashMap; struct Card { numbers : HashMap, - opens : Vec::>, + opens : [[bool; 5]; 5], score : u64, } impl Card { fn new() -> Card { - Card { numbers: HashMap::new(), opens: vec![vec![true; 5]; 5], score: 0 } + Card { numbers: HashMap::new(), opens: [[true; 5]; 5], score: 0 } } fn call(&mut self, n: u64) -> Option { @@ -43,19 +43,22 @@ impl Card { } fn check(&self, (x, y): (usize, usize)) -> bool { - for &b in &self.opens[x] { + let mut result_x = true; + let mut result_y = true; + + for b in self.opens[x] { if b { - return false; + result_x = false; } } for i in 0..self.opens.len() { if self.opens[i][y] { - return false; + result_y = false; } } - return true; + return result_x || result_y; } fn insert(&mut self, n: u64, coords: (usize, usize)) -> () { @@ -67,7 +70,7 @@ impl Card { fn main(){ println!("Advent of Code #4!\n"); - let path = Path::new("./3.txt"); + let path = Path::new("./4.txt"); let display = path.display(); let file = match File::open(&path) { @@ -79,12 +82,17 @@ fn main(){ let mut numbers = Vec::::new(); let mut bingo_cards = Vec::::new(); - let mut c = Card::new(); - c.insert(10, (1, 1)); - let r = c.call(10); + // let mut c = Card::new(); + // c.insert(1, (0, 1)); + // c.insert(2, (1, 1)); + // c.insert(3, (2, 1)); + // c.insert(4, (3, 1)); + // c.insert(5, (4, 1)); + + // assert_eq!(c.call(1), None); + // assert_eq!(c.call(2), None); + // assert_eq!(c.call(3), None); + // assert_eq!(c.call(4), None); + // assert_eq!(c.call(5), Some(0)); - match r { - None => println!("test failed"), - Some(t) => println!("test got: {}", t), - } } \ No newline at end of file