Skip to content

Instantly share code, notes, and snippets.

"""
MIT License
Copyright (c) 2023 Aimon Labs Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
"""
MIT License
Copyright (c) 2023 Aimon Labs Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@pjoshi30
pjoshi30 / weight_rbo_p.py
Last active January 11, 2021 06:24
WRBO[1:d] calculation to determine the value of p
import math
import numpy as np
p = 0.9
d = 10
def sum_series(p, d):
# tail recursive helper function
def helper(ret, p, d, i):
term = math.pow(p, i)/i
@pjoshi30
pjoshi30 / rbo_ext.py
Last active January 11, 2021 06:22
Simple RBO implementation in Python 3
import math
def rbo(list1, list2, p=0.9):
# tail recursive helper function
def helper(ret, i, d):
l1 = set(list1[:i]) if i < len(list1) else set(list1)
l2 = set(list2[:i]) if i < len(list2) else set(list2)
a_d = len(l1.intersection(l2))/i
term = math.pow(p, i) * a_d
if d == i:
return ret + term
@pjoshi30
pjoshi30 / pointEnumeration.java
Created May 14, 2016 02:11
Recursive backtracking code for point enumeration in an n-D space.
package com.yahoo.broadway.serving.actors;
import java.util.ArrayList;
import java.util.List;
//Creates duplicates :(
class PointEnumeration {
static class Point {
List<Float> dimensions; //a list of float where index i is the (i+1)'th dimension
@pjoshi30
pjoshi30 / weightedJobScheduling.java
Created March 3, 2016 04:46
O(n(log(n))) solution to the weighted job scheduling problem
import java.io.*;
import java.util.*;
/**
* nlogn solution to http://www.geeksforgeeks.org/weighted-job-scheduling/
*/
class Solution {
public static void main(String[] args) {
List<Job> jobs = Arrays.asList(new Job(3, 10, 20),new Job(1, 2, 50), new Job(6, 19, 100),new Job(2, 100, 200));
System.out.println("Max profit = " + findMax(jobs));
@pjoshi30
pjoshi30 / Upvotes.java
Created February 6, 2016 18:39
Quora upvotes challenge
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class Solution {
public static void main(String args[] ) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();