add framework for 93 (WIP)
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "euler93"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,64 @@
|
||||
type Num = f64;
|
||||
|
||||
fn main() {
|
||||
let digits = Digits(1., 2., 3., 4.);
|
||||
|
||||
let mut all_possible_integers = digits.all_possible_integers();
|
||||
|
||||
all_possible_integers.sort();
|
||||
|
||||
let mut result = 0;
|
||||
|
||||
for (i, num) in all_possible_integers.into_iter().enumerate() {
|
||||
if i + 1 == num as usize {
|
||||
result += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Digits(Num, Num, Num, Num);
|
||||
|
||||
impl Digits {
|
||||
fn all_possible_integers(&self) -> Vec<u32> {
|
||||
let a = self.0;
|
||||
let b = self.1;
|
||||
let c = self.2;
|
||||
let d = self.3;
|
||||
|
||||
let outcomes: Vec<_> = Operations::new()
|
||||
.map(|f| f(a, b) as u32)
|
||||
.filter(|i| *i > 0)
|
||||
.collect();
|
||||
|
||||
dbg!(outcomes)
|
||||
}
|
||||
}
|
||||
|
||||
struct Operations {
|
||||
last: usize,
|
||||
}
|
||||
|
||||
impl Iterator for Operations {
|
||||
type Item = Box<dyn FnOnce(Num, Num) -> Num>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.last += 1;
|
||||
match self.last {
|
||||
1 => Some(Box::new(|l, r| l + r)),
|
||||
2 => Some(Box::new(|l, r| l - r)),
|
||||
3 => Some(Box::new(|l, r| r - l)),
|
||||
4 => Some(Box::new(|l, r| l * r)),
|
||||
5 => Some(Box::new(|l, r| l / r)),
|
||||
6 => Some(Box::new(|l, r| r / l)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Operations {
|
||||
fn new() -> Self {
|
||||
Self { last: 0 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user