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
| 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) => |
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 "time" | |
| interface Fn | |
| fun apply() | |
| type Duration is U64 | |
| primitive Second | |
| fun apply(n: (U64 | USize)): Duration => | |
| match n |
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
| 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"]); | |
| } |
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
| #![macro_use] | |
| extern crate regex; | |
| use regex::Regex; | |
| #[derive(Debug)] | |
| enum Errors { | |
| BadFormat, | |
| } |
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
| extern crate regex; | |
| use regex::Regex; | |
| #[derive(Debug)] | |
| enum Errors { | |
| BadFormat, | |
| } | |
| use self::Errors::*; |
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
| 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) |
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
| 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) |
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
| // 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); |