Skip to content

Instantly share code, notes, and snippets.

View juanplopes's full-sized avatar
🌲
Is that a Segment Tree problem?

Juan Lopes juanplopes

🌲
Is that a Segment Tree problem?
View GitHub Profile
#include "stdio.h"
typedef struct tree tree;
struct tree{
int value;
tree *left ;
tree *right;
};
tree *tree_first_bigger(tree *t) {
@juanplopes
juanplopes / rainbow.py
Last active August 29, 2015 14:23
Python script to put a rainbow overlay in an image
#!/usr/bin/env python
import Image, colorsys, sys
if len(sys.argv) < 2:
print 'usage: {} <file> [<output>]'.format(sys.argv[0])
sys.exit(0)
img = Image.open(sys.argv[1])
width, height = img.size
let enumerateSquares (bitboard: uint64) =
bitboard
|> Seq.unfold(fun x ->
if x = 0UL then None
else Some(x &&& (~~~x + 1UL), x &&& (x - 1UL)))
let rec enumerateSquares (x: uint64) = seq {
if x<>0UL then
yield x &&& (~~~x+1UL)
yield! enumerateSquares(x &&& (x - 1UL))
}
def is_change_possible(coins, change):
if change==0: return True
if change<0 or len(coins)==0: return False
return (is_change_possible(coins[1:], change) or
is_change_possible(coins[1:], change-coins[0]))
print is_change_possible([1, 2, 5], 8)
print is_change_possible([1, 2, 5], 4)
print is_change_possible([1]*2000, 2000)
@juanplopes
juanplopes / keygen.py
Last active August 29, 2015 14:21
Simple Python script to help using GitHub pages as a Maven private repository
#!/usr/bin/env python
"""
GitHub keygen
Creates an OAuth2 token and adds a server entry at ~/.m2/settings.xml.
Makes it easy to either use a github private repository as a maven repository,
and to deploy artifacts to a private or public repository using github site
plugin.
"""
#include <iostream>
#include <queue>
#include <cmath>
using namespace std;
priority_queue<int> Q, T;
int main() {
int test=0, tests; cin >> tests;
int D;
@juanplopes
juanplopes / DefaultSchedulerContext.java
Created March 26, 2015 14:02
QConSP 2015: TaskScheduler
import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import com.google.common.primitives.Ints;
import com.google.common.primitives.Longs;
import java.util.List;
import java.util.PriorityQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@juanplopes
juanplopes / IntComparator.java
Created March 26, 2015 13:48
QConSP 2015: QuickSelect and stuff
public interface IntComparator {
public static final IntComparator DEFAULT = new IntComparator() {
@Override
public boolean lesser(int a, int b) {
return a < b;
}
};
public static final IntComparator REVERSE = new IntComparator() {
@Override
def solve(number, k):
n = len(number)
stack = []
for i, digit in enumerate(str(number)):
while stack and digit < stack[-1] and n-i+len(stack) > k:
stack.pop()
if len(stack) < n - k:
stack.append(digit)
return int(''.join(stack[:k]))