Skip to content

Instantly share code, notes, and snippets.

View jbowles's full-sized avatar
💭
working on it...

josh bowles jbowles

💭
working on it...
View GitHub Profile
@jbowles
jbowles / luhn_4_styles_julia.jl
Last active July 5, 2018 16:34
luhn in julia, 4 styles
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
@jbowles
jbowles / working_luhn_rust.rs
Created September 18, 2018 13:33
working_luhn_rust
//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;
/*
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.
*/
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: