Skip to content

Instantly share code, notes, and snippets.

Avatar

isaiah isaiah-perumalla

View GitHub Profile
@isaiah-perumalla
isaiah-perumalla / functions.py
Last active Nov 26, 2019
some python functions
View functions.py
def calc_avg(items):
if not items:
return 0
total = sum(items)
return float(total)/len(items)
def std_deviation(items):
if not items: return 0
mean = calc_avg(items)
@isaiah-perumalla
isaiah-perumalla / q-funcs.q
Last active Nov 6, 2019
some q functions
View q-funcs.q
//function return all subset of a list
sset: {[xs] (enlist ()) {x, (y,) each x }/ xs}
//or using the map each right /:
sset: {[xs] (enlist ()) {x, y ,/: x }/ xs}
//q)sset (1; 2; 3;`a)
()
,1
,2
2 1
View keybase.md

Keybase proof

I hereby claim:

  • I am isaiah-perumalla on github.
  • I am isaiahperumalla (https://keybase.io/isaiahperumalla) on keybase.
  • I have a public key whose fingerprint is E099 3317 C358 C9E7 6CD6 12C8 B55B AF0E 50E1 63B1

To claim this, I am signing this object:

@isaiah-perumalla
isaiah-perumalla / change.fs
Last active Dec 20, 2015
make change algorithm. compute change with using minimum number of coins
View change.fs
[<Measure>] type p
let count ps = let rec countcs acc = function
|[] -> acc
|(_, qty)::xs -> (countcs (acc+qty) xs)
in countcs 0 ps
let lessThan (x:int<p>) xs = List.filter (fun (coin, _) -> x >= coin) xs
let num_coins (coin:int<p>, qty:int) (amt:int<p>) = min qty (int(amt/coin))
let better ps bs =
@isaiah-perumalla
isaiah-perumalla / subpalindrome.py
Last active Dec 19, 2015
simple linear time algorithm for finding longest palindome substring in a give string
View subpalindrome.py
def longest_subpalindrome_slice(s):
longest=(0,0)
start_idx=0 #index of palindrone ending at i
repeated = True
#loop invariant we know longest palindrome in s[0:i]
#and we know longest palidrom ending at i
for i in xrange(1,len(s)):
if(start_idx != 0 and s[start_idx-1] == s[i]) :
start_idx = start_idx-1
repeated = False
View x86mfence.c
#include <pthread.h>
#include <stdio.h>
int x, y = 0;
int r0, r1;
void *core0 (void *arg)
{
x = 1;
asm volatile ("mfence" ::: "memory"); // ensure compiler or hardware will not reorder, store buffer is drained
View x86mmodel.c
#include <pthread.h>
#include <stdio.h>
int x, y = 0;
int r0, r1;
void *core0 (void *arg)
{
x = 1;
asm volatile ("" ::: "memory"); // ensure GCC compiler will not reorder
View longest_path.py
def solution(N, A, B, C):
edges = [(C[i],A[i],B[i]) for i in xrange(len(A))]
edges.sort(key=lambda e: e[0])
maxLenAt = [0]*N
costAt = [0]*N
def updatePath(u,costu,lenu, v,costv, lenv, cost):
if costu < cost and lenu+1 > lenv:
maxLenAt[v] = lenu+1
costAt[v] = cost
View twitter_water.py
def water_collected(A):
sortedHeights = [(x,i) for i,x in enumerate(A)]
sortedHeights.sort(key=lambda v: v[0]*-1) #sort in decreasing order
leftIdx = rightIdx = sortedHeights[0][1]
waterLevel = 0
for i in xrange(1,len(A)):
x,idx = sortedHeights[i]
if idx > rightIdx:
water = (idx-rightIdx-1)*x
View 10131_bigger_smarter.cc
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct Elephant {
int iq, weight, index;
static bool iq_greater(const Elephant& e1, const Elephant& e2) {
return e1.iq >= e2.iq;
}
};