Changed advent_of_code rust stuff to be good cargo packages instead

This commit is contained in:
2021-12-17 16:17:45 +01:00
parent 6533d3ccca
commit 7a8d39f5ca
16 changed files with 82 additions and 14 deletions

7
advent_of_code/d1/Cargo.lock generated Normal file
View File

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

View File

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

7
advent_of_code/d2/Cargo.lock generated Normal file
View File

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

View File

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

7
advent_of_code/d3/Cargo.lock generated Normal file
View File

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

View File

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

7
advent_of_code/d4/Cargo.lock generated Normal file
View File

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

View File

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

View File

@@ -14,13 +14,13 @@ use std::collections::HashMap;
struct Card {
numbers : HashMap<u64, (usize, usize)>,
opens : Vec::<Vec::<bool>>,
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<u64> {
@@ -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::<u8>::new();
let mut bingo_cards = Vec::<Card>::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),
}
}