Skip to content

Instantly share code, notes, and snippets.

View ibedwi's full-sized avatar
📚
Learning

Ibe Dwi ibedwi

📚
Learning
View GitHub Profile
@ibedwi
ibedwi / subsetPython.py
Created February 18, 2018 12:33
Find all possible subset in set a
# Example :
# a = [1,2,3]
# x = subset(a) * x=> [[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]
# x.sort() * x => [[], [1], [1, 2], [1, 2, 3], [1, 3], [2], [2, 3], [3]]
def subset(a):
if a == []:
return [[]]
i = subset(a[1:])
static int productOfSubsetSums(int arr[], int n)
{
int ans = 1;
for (int i = 0; i < n; ++i )
ans = ans * (arr[i] + 1);
return ans-1;
}
@ibedwi
ibedwi / matrixInverse.m
Created February 14, 2018 13:07
A singular or ill-conditioned matrix doesn't have inverse. But we can approximate its inverse using SVD.
% m is the matrix
% to check if a matrix has inverse or not, use det().
if det(m)~=0
% The matrix has inverse
minv = inv(m);
else
% The matrix doesn't has inverse
% Approximate the inverse using SVD
[U,S,V] = svd(m);
@ibedwi
ibedwi / printRange.py
Last active February 13, 2018 13:28
Print All number in range defined
from __future__ import print_function
# PRINT VALUE FROM S to N
s = int(raw_input())
n = int(raw_input())
print(*range(s,n+1),sep=' ')