Created
January 21, 2024 18:29
-
-
Save loreanvictor/c23894bb4c9ed15313458b6d265bc337 to your computer and use it in GitHub Desktop.
kaashi yaml
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
vec2d(x, y): | |
length: $ sqrt(x * x + y * y) | |
unitary op -: $ vec2d(-x, -y) | |
binary op + (other): $ vec2d(x + other.x, y + other.y) | |
binary op - (other): $ vec2d(x - other.x, y - other.y) | |
binary op * (other): $ x * other.x + y * other.y | |
binary op / (k): $ vec2d(x / k, y / k) | |
unitary op ^: $ self / length | |
unitary postfix op !: | |
(0): 1 | |
(n): $ n * (n - 1)! | |
fib: | |
(1): $ 1 | |
(2): $ 1 | |
(n): $ fib(n - 1) + fib(n - 2) | |
mean(arr): $ sum(arr) / arr.length | |
sum: | |
([x, ...rest]): $ x + sum(rest) | |
([]): 0 | |
map(f): | |
(arr): | |
length: $ f.length | |
[i]: $ f(arr[i], i, length) | |
filter(f): | |
([x, ...arr]): | |
$ f(x): $ [x, ...filter(f)(arr)] | |
$ otherwise: $ filter(f)(arr) | |
([]): [] | |
qsort: | |
([]): [] | |
([x, ...rest]): $| | |
[ | |
...filter(y -> y < x)(rest), | |
x, | |
...filter(y -> y > x)(rest), | |
] | |
merge: | |
([a, ...ar], [b, ...br]): | |
$ a < b: $ [a, ...merge(ar, [b, ...br])] | |
$ otherwise: $ [b, ...merge([a, ...ar], br)] | |
(l, []): $ l | |
([], l): $ l | |
sort: | |
([]): [] | |
([...left, ...right]): $| | |
merge( | |
sort(left), | |
sort(right) | |
) | |
index(x): | |
([]): -1 | |
([...left, center, ...right]): | |
$ center = x: $ left.length | |
$ center > x: $ index(x)(left) | |
$ center < x: $ left.length + 1 + index(x)(right) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment