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 std::cmp::Ordering; | |
use std::num::NonZeroUsize; | |
use std::{env, error::Error, ffi::OsStr, process}; | |
fn dot_product(xs: &[f32], ys: &[f32]) -> f32 { | |
xs.iter().zip(ys).map(|(&x, &y)| x * y).sum() | |
} | |
fn sigmoid(x: f32) -> f32 { | |
1.0 / (1.0 + (-x).exp()) |
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
#!/usr/bin/env elixir | |
defmodule KnapSack do | |
defmodule Item do | |
defstruct name: "", weight: 0, value: 0.0 | |
def new(name, weight, value), do: %Item{name: name, weight: weight, value: value} | |
end | |
def knapsack(items, max_capacity) when is_list(items) and is_integer(max_capacity) do | |
items_count = length(items) |
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
#!/usr/bin/env elixir | |
defmodule KMeans do | |
defprotocol DataPoint do | |
@type rand_dims :: list(float) | |
@spec dummy(t, rand_dims) :: t | |
def dummy(t, rand_dims) | |
@spec dimensions(t) :: list() | |
def dimensions(t) |
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
#!/usr/bin/env elixir | |
defmodule Chromosome do | |
@type t :: any() | |
@callback fitness(t) :: Float | |
@callback random_instance() :: t | |
@callback crossover(t, t) :: tuple() | |
@callback mutate(t) :: t | |
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
#!/usr/bin/env elixir | |
# Code.require_file("search_utils.exs", ".") | |
defmodule Edge do | |
defstruct from: nil, to: nil | |
def reversed(%Edge{from: f, to: t} = _edge), do: %Edge{from: t, to: f} | |
defimpl String.Chars do |
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
#!/usr/bin/env elixir | |
defprotocol Constraint do | |
@spec variables(t) :: nonempty_list() | |
def variables(t) | |
@type assignment() :: map() | |
@spec satisfied(t, assignment()) :: boolean() | |
def satisfied(t, assignment) | |
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
#!/usr/bin/env elixir | |
defmodule Stack do | |
def new(), do: [] | |
def push(stack, item) when is_list(stack) do | |
[item | stack] | |
end | |
def pop(stack) when is_list(stack) do |
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 crossterm::{ | |
cursor::{Hide, Show}, | |
execute, | |
terminal::{disable_raw_mode, enable_raw_mode}, | |
}; | |
use std::env; | |
use std::io::{self, Read, Write, stdin, stdout}; | |
const BG_COLORS: [u8; 12] = [253, 230, 229, 222, 215, 208, 202, 223, 221, 214, 209, 220]; | |
const FG_COLORS: [u8; 12] = [251, 232, 232, 232, 255, 255, 255, 232, 232, 255, 255, 232]; |
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
#!/usr/bin/env elixir | |
import Bitwise | |
defmodule Nucleotide do | |
defmodule NucWord do | |
defstruct u16: <<0::16>> | |
def parse(nucleotides) when is_binary(nucleotides) do | |
pat = Regex.compile!("^[_ACTGRKYMSWBDHVN]+$") |
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
#!/usr/bin/env elixir | |
Mix.install([ | |
{:evision, "~> 0.2.13"} | |
]) | |
alias Evision, as: Cv | |
alias Evision.Mat | |
alias Evision.CLAHE |
NewerOlder