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
# | |
# Run: ruby kendall_tau_distance.rb <filename1> <filename2> | |
# Given two files with values sorted according to their rank. Calcultae the KendallTau distance. | |
# This program considers all possible permuations of the given set, not scalable for a large set. | |
# | |
# Link to this file: https://gist.github.com/goyalankit/6755852 | |
if ARGV.length < 2 | |
p "please provide two files sorted based on rank values" | |
p "Usage: ruby kendall_tau_distance.rb <filename1> <filename2> " |
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
#include<iostream> | |
#include<vector> | |
#include<fstream> | |
#include<cmath> | |
#include<cstdlib> | |
#include <algorithm> | |
using namespace std; |
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
#include<iostream> | |
#include<algorithm> | |
using namespace std; | |
int main(int argc, char **argv){ | |
int list[9] = {10, -1, 5, 6, 20, -50, 100, -100, 4}; | |
int current_maximum = 0, previous_maximum=0; |
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
/* | |
*Author: Ankit Goyal | |
*Date: 10/12/2013 | |
* | |
*sample input: | |
* 2 | |
* hello | |
* ankitg | |
* | |
* output: |
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
# | |
# Author: Ankit Goyal | |
# Date: 10/26/2013 | |
# Spiral Matrix Traversal | |
# | |
class SpiralMatrixTraversal | |
def initialize n, m, y_start, x_start | |
@first = 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
# Found on the ZshWiki | |
# http://zshwiki.org/home/config/prompt | |
# | |
# Author: Ankit Goyal @_goyalankit | |
# | |
#Mimalistic Version(2 lines) | |
#PROMPT="%{$fg[red]%}%%%{$reset_color%} " | |
#RPROMPT='${time} %{$fg[cyan]%}%c%{$reset_color%}%{$reset_color%}' | |
grey='\e[0;90m' |
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
#include<iostream> | |
#include<regex> | |
#include<string> | |
int main(void){ | |
std::string num = "-23.43"; | |
if (std::regex_match (num, std::regex("^[+|-]{0,1}(\\d)*\\.?\\d+$") )) | |
std::cout << "it's a number" << std::endl; | |
else |
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
#y procedure calculates the frequency of each character in the string | |
y = Proc.new{|x| x.chars.group_by{|i| i}.values.collect{|i| i.count}} | |
z = Proc.new{|m,n| y.call(m) == y.call(n)} | |
z.call("foo", "app") | |
#the one liner, less readable..:) well technically two to make it general | |
y = Proc.new{|m,n| m.chars.group_by{|i| i}.values.collect{|i| i.count} == n.chars.group_by{|i| i}.values.collect{|i| i.count} } |
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
class BinaryTree | |
attr_accessor :left, :right, :data | |
def initialize data | |
@data = data | |
end | |
def self.create_tree | |
root = BinaryTree.new(3) | |
root.left = BinaryTree.new(9) |
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
5 5 | |
0 .1667 1 .1667 2 .1667 3 .1667 | |
2 .5 3 .3333 4 1 | |
0 .333 1 0.1667 2 0.6667 3 0.333 | |
1 .3333 2 .8333 3 .3333 4 .1667 | |
0 .5 1 .1667 2 .1667 3 .1667 |