Skip to content

Instantly share code, notes, and snippets.

View wuerges's full-sized avatar

Emilio Wuerges wuerges

  • Home
  • Santa Catarina - Brazil
View GitHub Profile
size = 100000
def f1():
lista = list(range(size))
eliminados = []
for i in lista:
if i%2 != 0:
eliminados.append(lista.pop(lista.index(i)))
#include <cstdio>
using namespace std;
struct Node {
long my_pos;
int valores[19] = {0};
long filhos[20];
bool folha() { return filhos[0] == -1; }
Node() {
for(int i = 0; i < 20; ++i) filhos[i] = -1;
import Data.Array.IArray
type G = Array Int [Int]
g1 :: G
g1 = array (1, 4) [[], [1], [1], [2, 3]]
preds :: Int -> G -> [Int]
preds x g = g !! x
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct UF {
vector<int> rank;
vector<int> root;
//=======================================================================
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <iostream>
#include <fstream>
int
main()
{
using namespace boost;
p1 = "<S> ::= a<A> | a<C> | b<B> | b<C>\n<A> ::= a<F> | a<G>\n<B> ::= b<F> | b<G>\n<C> ::= a<A> | a<C> | b<B> | b<C>\n<F> ::= a<F> | b<F> | a<G> | b<G>\n<G> ::= &\n"
p2 = p1.split('\n')
p3 = map(lambda x : x.split('::='), p2)
p4 = list(map(lambda x : list(map(lambda y: y.split('|'), x)), p3))
print(p4)
@wuerges
wuerges / knapsack.hs
Created May 23, 2017 01:57
Exemplo de programação dinâmica em Haskell
{- INPUT:
4 300
30 10
20 50
1 2
4 6
-}
{- OUTPUT:
900
-}
@wuerges
wuerges / UnionFind.hs
Created April 22, 2017 06:56
Union Find in Haskell, using the State Monad.
import Control.Monad.Trans.State.Strict
import Control.Monad
import Data.Ord
import Data.Maybe
import qualified Data.IntMap.Strict as M
data S = S { parentM :: M.IntMap Int
, rankM :: M.IntMap Int }
modifyP f = modify $ \s -> s { parentM = f (parentM s) }
@wuerges
wuerges / exbin.cc
Created April 21, 2017 19:14
Recursive Binary Exponentiation by fast doubling.
#include <iostream>
using namespace std;
int expbin(int a, int e, int m, int acc) {
if (e == 0) return acc;
if (e % 2 == 1) return expbin(a, e-1, m, (acc * a) % m);
return expbin((a * a) % m, e/2, m, acc);
}
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int xs[n];
int p_tam = 0;