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 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 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 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 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 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.Scanner; | |
// This is another problem submission from a programming practice. | |
// The problem description can be found here: | |
// http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=374&page=show_problem&problem=2697 | |
// Solved this one in approximately 1 hour. | |
public class Honeycomb { | |
public static void main(String[] args) { |
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
#!/usr/bin/env python | |
message = "010100000110100101100111001000000111100101101111011101010010011101110010011001010010000001100001001000000110010001101001011000110110101100101110" | |
bytes = [] | |
i = 0 | |
while i < len(message): | |
bytes.append( message[i:i+8] ) | |
i += 8 |
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 distance = distancePointToLineSegment(p, a, b) | |
% p is a point | |
% a is the start of a line segment | |
% b is the end of a line segment | |
pa_distance = sum((a-p).^2); | |
pb_distance = sum((b-p).^2); | |
unitab = (a-b) / norm(a-b); |
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 yes = thereIsACycle(G) | |
% G is an n-by-n association matrix. | |
% An edge is defined by anything in that | |
% matrix that is not 0 and not positive infinity. | |
% Elements along the diagonal are ignored. | |
% Returns 1 if there is a cycle. 0 otherwise. | |
yes = 0; | |
n = size(G, 1); | |
seen = zeros(1, 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
function [CENTERS, RADII] = tricenters(TRI, X, Y) | |
% This function takes the same parameters as the function 'trimesh' does, since they require the same inputs. | |
% INPUTS: | |
% TRI: A set of triangle indices. (N-by-3, where N is the number of triangles.) | |
% X: The X coordinate of the triangle indices. | |
% Y: The Y coordinate of the triangle indices. | |
% | |
% OUTPUTS: | |
% CENTERS: A 2D matrix of N-by-2, where N is the number of triangles in TRI. | |
% Each entry is a X, Y coordinate of a circumcenter. |
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 drawCircles(center,radius,NOP,style) | |
%------------------------------------------------------------------------------ | |
% CIRCLE(CENTER,RADIUS,NOP,STYLE) | |
% This routine draws a circle with center defined as | |
% a vector CENTER, radius as a scaler RADIS. NOP is | |
% the number of points on the circle. As to STYLE, | |
% use it the same way as you use the rountine PLOT. | |
% Since the handle of the object is returned, you | |
% use routine SET to get the best result. | |
% |