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
# This is not the actual Birthday Paradox Problem. | |
# This is something similar suggested by Taylor Smith. | |
# | |
# How many people do you need in a room to have a 50% | |
# chance of having every possible birthday represented | |
# within the room? | |
# | |
# After typing all of this out, I realized that it's | |
# the same as the Coupon Collector's Problem. |
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
function [m b] = linear_regression(X, Y) | |
n = length(Y); | |
EX = sum(X); | |
EY = sum(Y); | |
EX2 = sum(X.*X); | |
EXY = sum(X.*Y); | |
m = (n*EXY - EX*EY) / (n*EX2 - EX*EX); | |
b = (EY - m*EX) / n; | |
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
import java.util.*; | |
public class Tribute { | |
public static void main(String[] args) { | |
Scanner scan = new Scanner(System.in); | |
int datasets = scan.nextInt(); | |
scan.nextLine(); | |
for (int i = 0; i < datasets; i++) { | |
String original = scan.nextLine(); |
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
function yes = symmetric(g) | |
% Determins if an adjacency matrix | |
% is symmetric or not. | |
yes = 1; | |
[height width] = size(g); | |
if height ~= width | |
yes = 0; | |
end | |
for i = 1:height |
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
function result = connected(A) | |
% connected(A) | |
% | |
% This function takes an adjacency matrix A | |
% and returns if the graph is connected. | |
% 1 means connected. | |
% 0 means not connected. | |
% We assume that the starting result is connected. | |
% In lawyer terms, the graph is connected until proven |
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
function V = rotationMatrix(P, x, y, z) | |
% rotationMatrix performs the 3 axis rotation on a | |
% matrix P, which is a 3-by-p set of points, where | |
% d is equal to 3 and represents the dimensionality | |
% of the data and p represents the total number of | |
% observations. | |
% | |
% x represents the amount of rotation along the x axis in radians | |
% y represents the amount of rotation along the y axis in radians | |
% z represents the amount of rotation along the z axis in radians |
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
function newCurve = spline3d(curve, dt) | |
% interpote a 3d curve using spline | |
% path 3*x | |
% newPath 3*x | |
x = curve(1, :); | |
y = curve(2, :); | |
z = curve(3, :); | |
t = cumsum([0;sqrt(diff(x(:)).^2 + diff(y(:)).^2 + diff(z(:)).^2)]); | |
sx = spline(t,x); | |
sy = spline(t,y); |
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
function gplot3(A, xyz) | |
% GPLOT3(A, xyz) is nearly the same as GPLOT(A, xy) except | |
% that the xyz variable requires a third dimension. | |
% This function takes an adjacency matrix and visualizes it | |
% in 3D. | |
[d e] = size(A); | |
if d ~= e | |
error('A matrix must be square.'); | |
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
function D = dijkstra(G, pairs) | |
% This function takes an adjacency matrix called G | |
% and a p-by-2 matrix called pairs. | |
% The pairs matrix will contain pairs of indices. | |
% This function will determine the shortest distance from | |
% the first index in the pair to the second index for | |
% every pair in matrix pairs. | |
% | |
% The function will only return a p-by-1 matrix of shortest | |
% distances. I could use it to also return the shortest path, |
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
""" | |
This code computes pi. It's not the first python | |
pi computation tool that I've written. This program | |
is a good test of the mpi4py library, which is | |
essentially a python wrapper to the C MPI library. | |
To execute this code: | |
mpiexec -np NUMBER_OF_PROCESSES -f NODES_FILE python mpipypi.py |