Skip to content

Instantly share code, notes, and snippets.

class BinaryHeap[T: Comparable[T] #read]
let _data: Array[T]
new create() =>
_data = Array[T]
fun apply(): this->T ? =>
_data(0)?
fun ref push(item: T) =>
use "time"
interface Fn
fun apply()
type Duration is U64
primitive Second
fun apply(n: (U64 | USize)): Duration =>
match n
fn main() {
let arr_num = vec![16, 3, 8, 16, 4, 4, 3, 1, 16];
assert_eq!(array_unique(&arr_num), [1, 3, 4, 8, 16]);
let arr_str = vec!["ab", "ba", "cd", "ba", "aa", "dd", "ba", "cd", "aa"];
assert_eq!(array_unique(&arr_str), ["aa", "ab", "ba", "cd", "dd"]);
}
#![macro_use]
extern crate regex;
use regex::Regex;
#[derive(Debug)]
enum Errors {
BadFormat,
}
extern crate regex;
use regex::Regex;
#[derive(Debug)]
enum Errors {
BadFormat,
}
use self::Errors::*;
sum'n'count :: Integer -> (Integer, Integer)
sum'n'count 0 = (0, 1)
sum'n'count x = helper (abs x) 0 0
where
helper 0 sum count = (sum, count)
helper n sum count = let num = (n `div` 10)
in helper num (sum + n - num * 10) (count + 1)
integration :: (Double -> Double) -> Double -> Double -> Double
integration f a b = h * ((f a + f b) / 2 + sum 0 (n - 1))
where
n = 1000
h = (b - a) / n
sum result 0 = result
sum result iter = sum (result + f (a + iter * h)) (iter - 1)
@glaznaj
glaznaj / tree.dart
Last active January 19, 2016 10:27
Dart version of tree.ts
// tree.ts https://gist.github.com/dmitry-vsl/ab40c3b325bcf0a0eb07
// Run it in Dartpad: https://dartpad.dartlang.org/1a4a46dce98278473255
class Tree<T> {
final Tree<T> left;
final Tree<T> right;
final T value;
Tree(this.left, this.right, this.value);