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
using BenchmarkTools | |
dbl2nd(da::Array{Int64,1}) = for i in 1:2:(length(da)) | |
da[i] *= 2 | |
end | |
mod9(da::Array{Int64,1}) = for i in 1:2:length(da) | |
if da[i] > 9 | |
da[i] -= 9 | |
end |
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
//Luhn trait | |
pub trait Luhn { | |
fn luhn(self) -> bool; | |
} | |
impl Luhn for String { | |
fn luhn(self) -> bool { | |
let s = remove_whitespace(&self); | |
let d = Digits::digits(s); | |
if d.len() < 16 { | |
return false; |
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
/* | |
RatcliffObserhelp distance | |
SEE tokenizer | |
[NIST Ratcliff/Obershelp pattern recognition](https://xlinux.nist.gov/dads/HTML/ratcliffObershelp.html): | |
Compute the similarity of two strings as the number of matching characters divided by the total number of characters in the two strings. | |
Matching characters are those in the longest common subsequence plus, recursively, matching characters in the unmatched region on either side of the longest common subsequence. | |
*/ |
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
package metron | |
import "math" | |
// CosineSim calculate the similarity of two non-zero vectors using dot product (multiplying vector elements and summing) and deriving the cosine angle between the two vectors. | |
// TODO not fully tested yet! | |
// | |
// Dot Product: | |
// \vec{a} = (a_1, a_2, a_3, \ldots), \vec{b} = (b_1, b_2, b_3, \ldots); where a_n and a_b are elements of the vector. | |
// Cosine Similarity: |
OlderNewer