This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use num_bigint::BigUint; | |
| use num_traits::ToPrimitive; | |
| // calculate the binomial coefficient `n choose k` | |
| fn binomial_coefficient(n: u32, k: u32) -> u64 { | |
| let mut result = BigUint::from(1u32); | |
| for i in 0..k { | |
| result = (result * (n - i)) / (i + 1); | |
| } | |
| result.to_u64().unwrap() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn binomial_coefficient(n: u32, k: u32) -> u128 { | |
| let mut res = 1u128; | |
| for i in 0..k { | |
| res = (res * (n - i) as u128) / (i + 1) as u128; | |
| } | |
| res | |
| } | |
| fn neg_binom_pmf(k: u32, r: u32, p: f64) -> f64 { | |
| assert!(r > 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn binomial_coefficient(n: u32, k: u32) -> u128 { | |
| let mut res = 1u128; | |
| for i in 0..k { | |
| res = (res * (n - i) as u128) / (i + 1) as u128; | |
| } | |
| res | |
| } | |
| fn neg_binom_pmf(k: u32, r: u32, p: f64) -> f64 { | |
| assert!(r > 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Calculate the area of a generalized ellipse (abs(x/a)^n + abs(y/b)^n = 1). | |
| // I'm considering this as the metric to minimize for a weird optimization | |
| // problem, where this would be evaluated _a lot_, so I tried making this | |
| // as fast & simple as possible. | |
| pub fn area_of_superellipse(exponent: f64, semi_axes: (f64, f64)) -> f64 { | |
| let n = exponent; | |
| let (a, b) = semi_axes; | |
| // This method was derived from the following formula: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Const evaluatable Rust implementation of Vose's Alias Method, as described | |
| /// by Keith Schwarz at https://www.keithschwarz.com/darts-dice-coins/ | |
| /// | |
| /// In brief, this is an O(n) precomputation, which allows sampling an arbitrary | |
| /// finite probability distribution in O(1) time, by first simulating a fair | |
| /// n-sided die, followed by a biased coin. | |
| /// | |
| /// Because floating point arithmetic cannot be used in const functions, this is | |
| /// built to operate on integer weights, rather than precomputed probabilities. | |
| /// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use scraper::{Html, Selector}; | |
| use std::collections::HashMap; | |
| fn main() { | |
| let source_sites: &[&[&str]] = &[ | |
| &[ | |
| "https://tvtropes.org/pmwiki/pmwiki.php/BreakingBad/TropesAToB", | |
| "https://tvtropes.org/pmwiki/pmwiki.php/BreakingBad/TropesCToD", | |
| "https://tvtropes.org/pmwiki/pmwiki.php/BreakingBad/TropesEToL", |
OlderNewer