格式化,y不动点算子
This commit is contained in:
parent
179d4698ad
commit
f48bf131dd
|
@ -12,8 +12,8 @@ mod q0006;
|
|||
mod q0007;
|
||||
mod q0008;
|
||||
mod q0009;
|
||||
mod q0012;
|
||||
mod q0011;
|
||||
mod q0012;
|
||||
mod q0013;
|
||||
mod q0014;
|
||||
mod q0020;
|
||||
|
@ -51,9 +51,9 @@ mod q0101;
|
|||
mod q0102;
|
||||
mod q0104;
|
||||
mod q0108;
|
||||
mod q0112;
|
||||
mod q0110;
|
||||
mod q0111;
|
||||
mod q0112;
|
||||
mod q0118;
|
||||
mod q0119;
|
||||
mod q0121;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#![allow(dead_code)]
|
||||
//! 目前此文件用于临时测试、将来将提供所有题目的入口
|
||||
const MASK_LOOKUP: [[u128; 5]; 5] = [
|
||||
[0x00000000ffff0000000000000000ffff_u128, 0x000000000000000000000000ffff0000_u128, 0x000000000000ffff0000000000000000_u128, 0x00000000000000000000ffff00000000_u128, 0x0000000000000000ffff000000000000_u128],
|
||||
|
@ -24,20 +25,63 @@ pub fn re_three(mut a: u128) -> (u32, u32, u32) {
|
|||
((a >> 64) as u32, (a >> 32) as u32, a as u32)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
pub fn test_speed() {
|
||||
use std::time::Instant;
|
||||
let t1 = Instant::now();
|
||||
let t = 10000000;
|
||||
for _ in 0..t {
|
||||
three(0, 0xffffffffu32, 0);
|
||||
for i in 0..t {
|
||||
three(i, 0xffffffffu32, i);
|
||||
}
|
||||
println!("{}", t1.elapsed().as_millis());
|
||||
/*let contents = std::fs::read_to_string("F:\\MyProject\\my_leetcode\\rust\\src\\implements\\mod.rs").expect("Something went wrong reading the file");
|
||||
}
|
||||
|
||||
struct Func<'a, A, F>(&'a dyn Fn(Func<'a, A, F>, A) -> F);
|
||||
|
||||
impl<'a, A, F> Clone for Func<'a, A, F> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, A, F> Copy for Func<'a, A, F> {}
|
||||
|
||||
impl<'a, A, F> Func<'a, A, F> {
|
||||
fn call(&self, f: Func<'a, A, F>, x: A) -> F {
|
||||
(self.0)(f, x)
|
||||
}
|
||||
}
|
||||
|
||||
fn y<A, R>(g: impl Fn(&dyn Fn(A) -> R, A) -> R) -> impl Fn(A) -> R {
|
||||
move |x: A| {
|
||||
(|f: Func<A, R>, x| f.call(f, x))(
|
||||
Func(&|f: Func<A, R>, x: A| g(&|x: A| f.call(f, x), x)),
|
||||
x,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn test_y() {
|
||||
let fact = y(|f: &dyn Fn(usize) -> usize, x: usize| match x {
|
||||
0usize => 1usize,
|
||||
1usize => 1usize,
|
||||
_ => f(x - 2) + f(x - 1),
|
||||
});
|
||||
println!("{}", fact(10usize));
|
||||
}
|
||||
|
||||
fn reformat() {
|
||||
let contents = std::fs::read_to_string("F:\\MyProject\\my_leetcode\\rust\\src\\implements\\mod.rs").expect("Something went wrong reading the file");
|
||||
let mut arr = contents.split("\r\n").collect::<Vec<&str>>();
|
||||
arr.sort_unstable();
|
||||
|
||||
for item in arr {
|
||||
println!("{}", item);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test_speed();
|
||||
test_y();
|
||||
reformat();
|
||||
//println!("{:0128b}", a);
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
|
Loading…
Reference in New Issue