Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View goyalankit's full-sized avatar
🏠
Working from home

Ankit Goyal goyalankit

🏠
Working from home
View GitHub Profile
@goyalankit
goyalankit / kendall_tau_distance.rb
Created September 29, 2013 19:45
Calculate the Kendall tau distance for two files sorted according to their rank.
#
# 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> "
@goyalankit
goyalankit / sort_two_colum_file.cpp
Created October 1, 2013 21:19
Sorts the two column file based on the second column.
#include<iostream>
#include<vector>
#include<fstream>
#include<cmath>
#include<cstdlib>
#include <algorithm>
using namespace std;
@goyalankit
goyalankit / maximum_sum.cpp
Created October 11, 2013 05:06
Maximum Sum Problem
#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;
@goyalankit
goyalankit / string_transposition.cpp
Last active December 25, 2015 09:49
Method to transpose string
/*
*Author: Ankit Goyal
*Date: 10/12/2013
*
*sample input:
* 2
* hello
* ankitg
*
* output:
#
# Author: Ankit Goyal
# Date: 10/26/2013
# Spiral Matrix Traversal
#
class SpiralMatrixTraversal
def initialize n, m, y_start, x_start
@first = n
@goyalankit
goyalankit / ankit-imajes.zsh-theme
Last active December 27, 2015 08:09
Customized imajes theme. Minimalistic version.
# 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'
@goyalankit
goyalankit / isnum.cpp
Created November 8, 2013 01:45
Method to check if given string is a number or not.
#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
@goyalankit
goyalankit / ismorphic_mapping.rb
Last active December 27, 2015 19:19
isomorphic mapping
#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} }
@goyalankit
goyalankit / level_order_print.rb
Created November 11, 2013 20:13
Level order print.
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)
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