Skip to content

Instantly share code, notes, and snippets.

@kamalbanga
kamalbanga / LegoBlocks.cpp
Last active March 10, 2019 17:37
A dynamic programming/recursive solution to Hackerrank's "Lego Blocks" problem.
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
#define MOD 1000000007
unsigned long long power(unsigned long long num, int p) {
@kamalbanga
kamalbanga / numberofOnes.c
Last active December 26, 2015 03:19
Total no. of 1's in 2's complement representation between A and B, inclusive. Hackerrank's "2's complement" problem.
#include <stdio.h>
#include <math.h>
#include <limits.h>
unsigned int prevTwo(unsigned int x) // bit twiddling
{
unsigned int y = x;
x--;
x |= x >> 1;
x |= x >> 2;
@kamalbanga
kamalbanga / postorder.c
Last active December 27, 2015 11:59
Create Binary Tree from it's PostOrder when leaf nodes are differentiable from internal nodes and internal nodes have exactly two children.
#include <stdio.h>
#include <stdlib.h>
struct node
{
char c;
struct node* left, *right;
};
struct node* createNode(char c)
@kamalbanga
kamalbanga / ACO.py
Last active March 29, 2017 10:23
To find TSP through Ant Colony Optimization
import random
import math
seed = 1
boost = 5
iter = 3
numCities = 4
maxDistance = 40000
upperX = 24000
upperY = 32000
@kamalbanga
kamalbanga / ACO2.py
Last active August 29, 2015 13:57
Vehicle Routing Problem
import random
import math
import numpy as np
seed = 1
boost = 20
maxIter = 50
numCities = 15
mu, sigma = 500, 200
demand = np.random.normal(mu,sigma,numCities)
@kamalbanga
kamalbanga / glift.cpp
Created April 8, 2014 19:48
GLIFT Simulation
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <string.h>
#include <fstream>
#include <queue>
#include <ctime>
#include <algorithm>
using namespace std;
import random
import math
import numpy as np
seed = 1
boost = 20
maxIter = 50
numCities = 15
mu, sigma = 500, 200
demand = np.random.normal(mu,sigma,numCities)

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@kamalbanga
kamalbanga / copyMul.py
Last active August 29, 2015 14:03
Copy a file into multiple files in Python.
import os, sys, shutil
DUP = 10
file = sys.argv[1]
path, fileName = os.path.split(file)
file_name, file_extension = os.path.splitext(fileName)
for i in range(1, DUP+1):
shutil.copyfile(file,path+'/'+file_name+'_'+str(i)+file_extension)
@kamalbanga
kamalbanga / git.md
Created July 24, 2014 13:43
Git commands

INITIALISING

$ git init [project-name] Creates a new local repository with the specified name

$ git clone https://github.com/[organization]/[repository].git Clones the repo into a new filder named ‘repository’

$ git status