Skip to content

Instantly share code, notes, and snippets.

View mh-github's full-sized avatar

Mahboob Hussain mh-github

View GitHub Profile
require 'nmatrix'
require 'pp'
###############################################################################
=begin
@INPUT:
r : a matrix to be factorized, dimension n x m
p : an initial matrix of dimension n x k
q : an initial matrix of dimension m x k
#!/usr/bin/python
#
# Created by Albert Au Yeung (2010)
#
# An implementation of matrix factorization
#
try:
import numpy
except:
print "This implementation requires the numpy module."
NUM = 2000
pow, val = [], []
2.upto NUM-1 do |num|
0.upto(NUM-1) {|i| pow[i] = 0 }
count, ten, x = 0, 1, 1
while (x < NUM) do
val[x] = ten
0.upto NUM-1 do |j|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
public class n_multiple_Min_N_Zeros_Ones
{
#include <stdio.h>
#define NUM 2000
int main(int argc, char* argv[])
{
signed long pow[NUM],val[NUM],x,num,ten;
int i,j,count;
for(num=2; num<NUM; num++)
{
for(i=0; i<NUM; pow[i++]=0);
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Solution {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long n = 0;
@mh-github
mh-github / fiful.rb
Created February 21, 2015 19:56
Ruby example for function in a function by using lambda
def outer(a)
b = 6
l = lambda do |a, b|
print a + b
end
l.call(a, b)
end
outer(5)
@mh-github
mh-github / pdg.rb
Created February 21, 2015 19:34
Ruby version of Dendrogram drawing (Python recipe) from http://code.activestate.com/recipes/139422-dendrogram-drawing/
def printDendrogram(t, sep=3)
isPair = lambda do |t|
return t.class == Array && t.length == 2
end
maxHeight = lambda do |t|
if isPair.call(t)
h = [maxHeight.call(t[0]), maxHeight.call(t[1])].max
else
@mh-github
mh-github / pdg.py
Created February 21, 2015 19:32
# Dendrogram drawing (Python recipe) from http://code.activestate.com/recipes/139422-dendrogram-drawing/ def printDendrogram(T, sep=3): """Print dendrogram of a binary tree. Each tree node is represented by a length-2 tuple.""" def isPair(T): return type(T) == tuple and len(T) == 2 def maxHeight(T): if isPair(T): h = max(maxHeight(T[0]), maxHeig…
# Dendrogram drawing (Python recipe) from http://code.activestate.com/recipes/139422-dendrogram-drawing/
def printDendrogram(T, sep=3):
"""Print dendrogram of a binary tree. Each tree node is represented by a length-2 tuple."""
def isPair(T):
return type(T) == tuple and len(T) == 2
def maxHeight(T):
if isPair(T):
@mh-github
mh-github / mh_util.rb
Created October 26, 2014 09:14
Ruby utility module to simulate a Python tuple to be used for sorting
module MH_util
Tuple = Struct.new(:first, :second) do
def <=>(other)
return second <=> other.second if first == other.first
first <=> other.first
end
def to_s
"(#{first}, #{second})"
end