This file contains 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
function q = cauchyEstimator(x) | |
N = numel(x); | |
A = @(t) sum(1 ./ (t(1) - x + t(2) .^ 2) .^ 2); | |
B = @(t) 2 * t(2) * sum(1 ./ (t(1) - x + t(2) .^ 2) .^ 2); | |
D = @(t) -(N - 2 * sum(1 ./ (t(1) - x + (t(2) ^ 2)) .^ 2 .* ((t(2) .^ 2) - t(1) + x)) * t(2) .^ 2) ./ t(2) .^ 2; | |
J = @(t) [A(t) B(t); B(t) D(t)]; | |
F = @(t)[-sum((2 * t(1) - 2 .* x) ./ ((t(1) - x) .* (t(1) - x) + t(2)*t(2))),N/t(2)-sum(2*t(2)./((t(1)-x).^2+t(2)^2))]; | |
This file contains 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
from itertools import combinations as C | |
def numberOfTriangles2(s): | |
s = sorted(s) | |
return sum(sum(1 for _ in filter(lambda r: s[x-1] < sum(r),C(s[:x-1],2))) for x in range(3,len(s)+1)) |
This file contains 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
function fibFib(f) result(r) | |
implicit real(8) (t-z) | |
integer :: f,n | |
logical :: r | |
n = 0 | |
r = .false. | |
do | |
v = sqrt(5D0) / 2 | |
w = (3 / 2D0 - v) ** n |
This file contains 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
bool isTriangle(auto p) { | |
return fmod((1+8*p)/2,1)<.1; | |
} |
This file contains 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
r = math.sqrt(5) | |
def fibAt(n): | |
B = (1-r)/2; | |
A = (1+r)/2; | |
return "{}".format(int(.5+(A ** n + B ** n)/r) ** n if n > 1 else 1) |
This file contains 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
wallisFormula = @(n) sqrt(pi)*gamma((n+1)/2)/(n*gamma(n/2)); |
This file contains 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
function isTournament(n, A, B) result(o) | |
implicit integer (a-z) | |
type(ArrayInteger) :: A, B | |
logical :: o | |
o = .false. | |
if(n<2) return | |
s = size(A%arr) | |
do i=1,s | |
if (A%arr(i)==B%arr(i)) return |
This file contains 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
#define A(z) r[(3+z)&3] | |
auto monkeyBars(auto n) { | |
int64_t r[4] = {0,0,1},i=0; | |
while(i<n) A(i++) = A(i-1) + A(i-2) +A(i-3); | |
return A(n-1); | |
} |
This file contains 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
/*You are given an n × m matrix, which contains all the integers from 1 to n * m, inclusive, each exactly once. | |
Initially you are standing in the cell containing the number 1. On each turn you are allowed to move to an adjacent cell, i.e. to a cell that shares a common side with the one you are standing on now. It is prohibited to visit any cell more than once. | |
Check if it is possible to visit all the cells of the matrix in the order of increasing numbers in the cells, i.e. get to the cell with the number 2 on the first turn, then move to 3, etc.*/ | |
bool findPath(auto& m, int p = 1, int i=0, int j=0) { | |
int x = m.size(),y = m[0].size(),k; | |
if(p==x*y) return 1; | |
if(p==1) | |
for(i = 0; i < x;++i) |
This file contains 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
FUNCTION HYPERLOOP(C1, C2, TU) | |
IMPLICIT INTEGER (A-Z) | |
CHARACTER(:), ALLOCATABLE :: C1, C2 | |
TYPE(ARRAYARRAYSTRING) :: TU | |
TYPE(STRING), DIMENSION(99) :: NA | |
INTEGER, DIMENSION(:,:), ALLOCATABLE :: AD, AT | |
INTEGER, DIMENSION(:), ALLOCATABLE :: DI, Q | |
! CONSTRUCT ID TO NAME MAPPING... | |
J = 0 |