Ëerste poging projecteuler 90
This commit is contained in:
18
projecteuler/090/Cargo.lock
generated
18
projecteuler/090/Cargo.lock
generated
@@ -2,6 +2,24 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "either"
|
||||||
|
version = "1.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "main"
|
name = "main"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"itertools",
|
||||||
|
]
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
itertools = "0.12.1"
|
||||||
|
|||||||
@@ -1,10 +1,68 @@
|
|||||||
|
use itertools::Itertools;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
fn generate_cubes() -> Vec<Vec<u32>> {
|
||||||
|
(0..=9).combinations(6).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_valid_dice_configuration(d1: &Vec<u32>, d2: &Vec<u32>) -> bool {
|
||||||
|
let necessary_matches: Vec<_> = [
|
||||||
|
(0, 1),
|
||||||
|
(0, 4),
|
||||||
|
(0, 9),
|
||||||
|
(1, 6),
|
||||||
|
(2, 5),
|
||||||
|
(3, 6),
|
||||||
|
(4, 9),
|
||||||
|
(6, 4),
|
||||||
|
(8, 1),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
for (m1, m2) in necessary_matches {
|
||||||
|
if !(d1.contains(&m1) && d2.contains(&m2) || d1.contains(&m2) && d2.contains(&m1)) {
|
||||||
|
if m1 == 6 {
|
||||||
|
if !(d1.contains(&9) && d2.contains(&m2) || d1.contains(&m2) && d2.contains(&9)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if m2 == 6 {
|
||||||
|
if !(d1.contains(&m1) && d2.contains(&9) || d1.contains(&9) && d2.contains(&m2)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if m2 == 9 {
|
||||||
|
if !(d1.contains(&m1) && d2.contains(&6) || d1.contains(&6) && d2.contains(&m2)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, this is Patrick!");
|
println!("Hello, this is Patrick!");
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
// We can't just loop through all possibilities because that would something in the order of
|
|
||||||
// (10*9*8*7*6*5)^2, which is a really big scary number
|
let dice1 = generate_cubes();
|
||||||
|
let dice2 = generate_cubes();
|
||||||
|
|
||||||
|
assert_eq!(dice1.len(), 210);
|
||||||
|
|
||||||
|
let mut result = 0;
|
||||||
|
|
||||||
|
for d1 in dice1.iter() {
|
||||||
|
for d2 in dice2.iter() {
|
||||||
|
if is_valid_dice_configuration(d1, d2) {
|
||||||
|
result += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Number of valid configurations of dice is {}", result);
|
||||||
|
|
||||||
println!("Time passed: {:?}", Instant::now() - now);
|
println!("Time passed: {:?}", Instant::now() - now);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user