use crate::impl_number_utils_for;
use std::marker::Sized;
impl_number_utils_for!(u32, u64, u128, usize);
pub trait NumberUtils {
fn factorial(&self) -> Self;
fn permutation(&self, k: u32) -> Self;
fn combination(&self, k: u32) -> Self;
fn gcd(&self, m: Self) -> Self;
fn lcm(&self, m: Self) -> Self;
fn isqrt(&self) -> Self;
fn checked_factorial(&self) -> Option<Self>
where
Self: Sized;
fn checked_permutation(&self, k: u32) -> Option<Self>
where
Self: Sized;
fn checked_combination(&self, k: u32) -> Option<Self>
where
Self: Sized;
fn digits(&self) -> Self;
}
pub fn pascals_triangle(n: usize) -> Vec<usize> {
let mut result = vec![1];
for i in 1..n {
let r = result.len() - i;
result.push(1);
for j in 1..i {
result.push(result[r + j - 1] + result[r + j]);
}
result.push(1);
}
result
}