I can only rebind a variable that is explicitly declared as mutable; cool.
fn main() {
let mut x: int = 5;
x = 10i;
println!("value of x: {}", x); // -> 10
}| 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: |
| /* | |
| 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. | |
| */ |
| //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; |
| 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 |
| #load "../packages/FsLab/FsLab.fsx" | |
| (* My Environment | |
| visual studio code 2017 Version 1.18.1 | |
| mono --version ‹2.4.1› | |
| Mono JIT compiler version 5.4.1.7 (2017-06/e66d9abbb27 Wed Oct 25 12:10:41 EDT 2017) | |
| Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com | |
| TLS: normal | |
| SIGSEGV: altstack |
| defmodule Mather do | |
| def numbers(x,y) do | |
| f = fn | |
| x,y when x>0 -> x + y | |
| x,y -> x*y | |
| end | |
| IO.puts f.(x,y) | |
| end | |
| # A tail call optimized fibonacci. |
| // Using the Unicode Names package: http://www.rust-ci.org/huonw/unicode_names/doc/unicode_names/#cargo-enabled | |
| //require macros... | |
| // in Cargo.toml looks like this: | |
| // [dependencies.unicode_names_macros] | |
| // git = "https://github.com/huonw/unicode_names" | |
| #![feature(phase)] | |
| #[phase(plugin)] extern crate unicode_names_macros; |
I can only rebind a variable that is explicitly declared as mutable; cool.
fn main() {
let mut x: int = 5;
x = 10i;
println!("value of x: {}", x); // -> 10
}| defmodule WordCounter do | |
| def count(sent) do | |
| sent |> normalize |> find_words |> count_unique |> Enum.sort() | |
| end | |
| def find_words(sent) do | |
| Regex.scan(~r/\w+/, sent) | |
| end |
| ### Keybase proof | |
| I hereby claim: | |
| * I am jbowles on github. | |
| * I am jbowles (https://keybase.io/jbowles) on keybase. | |
| * I have a public key whose fingerprint is 18A2 A842 FEB6 3E60 3CB3 AC80 3A7B 98D5 D2AA FE72 | |
| To claim this, I am signing this object: |