Skip to content

Instantly share code, notes, and snippets.

💭
It's probably about Segment Trees

Juan Lopes juanplopes

💭
It's probably about Segment Trees
Block or report user

Report or block juanplopes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@juanplopes
juanplopes / generate.py
Created Nov 3, 2016
Generates ILP problem to be solved by glpsol
View generate.py
from collections import defaultdict
def name1(i):
return chr(ord('A')+i)
def name2(x, n):
return ''.join(name1(i) for i in xrange(n) if x&(1<<i))
def print_model(L, U, n, G):
for x in range(1, 2**n):
View test.cpp
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int T[100];
vector<set<int> > V;
bool test(int C, set<int> &X, set<int> &Y) {
int count = 0;
@juanplopes
juanplopes / download.py
Created Oct 23, 2016
Downloads problems, best submissions and leaderboard from IEEExtreme 10 competition
View download.py
#!/usr/bin/env python2
from collections import defaultdict
import requests, json, zipfile
PREFIX = 'https://ieee.hackerrank.com/rest/contests/ieeextreme10'
USER='PUT USERNAME HERE'
PASS='PUT PASSWORD HERE'
EXT = {'python': 'py'}
@juanplopes
juanplopes / UpdateHeap.java
Created Jul 28, 2016
Modifiable binary heap
View UpdateHeap.java
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
public class UpdateHeap<V> implements Iterable<V> {
private final Comparator<V> comparator;
private final HashMap<V, Entry> map;
private Entry[] heap;
View gist:558a46c06eb52aeff5c64a3861943105
def push(stack, el): stack+(el,);
def pop(stack): (stack:take(len(stack)-1), stack:get(len(stack)-1));
def memset(state, key, value): (state |> @filter({0}!=key)) + ((key, value),);
def memget(state, key): state |> last({1}):if({0}==key)# ?? 0;
def memadd(state, key, value): memset(state, key, memget(state, key)+value);
def findclosing(code, i):
(1, i+1):unfold(fun(count, i):
i >= len(code) or count == 0 ? null,
code:get(i) == '[' ? (i, (count+1, i+1)),
@juanplopes
juanplopes / Main.java
Created Feb 18, 2016
Object Pool example
View Main.java
package example;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class Main {
public static void main(String... args) throws Exception {
ObjectPool<ExpensiveObject> pool = new ObjectPool<ExpensiveObject>() {
@Override
View test.cpp
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
struct Dist {
int node, d;
Dist(int node, int d) : node(node), d(d) { }
};
View clever.md

Remember

This is ok:

for(int i = 1; i <= floor(sqrt(n)); i++) {
    //code
}
View gist:64f9dbb4e16e3d5a73b2
100 1073741823
1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
View cpf.py
def next_digit(value, base):
return value + str(sum(int(a)*b for a,b in zip(value, base))%11%10)
def make_valid(value, ap2, base):
return next_digit(next_digit(value, base), ap2+base)
def is_valid_cpf(cpf):
return make_valid(cpf[:9], [0], [1,2,3,4,5,6,7,8,9]) == cpf
def is_valid_cnpj(cnpj):
You can’t perform that action at this time.