Skip to content

Instantly share code, notes, and snippets.

View DavideCanton's full-sized avatar

Davide Canton DavideCanton

View GitHub Profile
@DavideCanton
DavideCanton / quadtree.py
Created May 1, 2014 12:57
Quad Tree Python implementation.
__author__ = 'davide'
from collections import namedtuple, deque
from random import randint
import sys
import itertools as it
class Rect(namedtuple("_Rect", "x, y, w, h")):
def __contains__(self, point):
__author__ = 'Kami'
from collections import defaultdict
import itertools as it
class MappingError(Exception):
pass
@DavideCanton
DavideCanton / pyng.py
Last active August 29, 2015 13:57
Python tool for pinging hosts
__author__ = "davide"
import struct
import socket
import argparse
import sys
from datetime import datetime
import time
from collections import defaultdict
from signal import signal, SIGINT, SIG_IGN
@DavideCanton
DavideCanton / unionfind.py
Created February 23, 2014 15:55
Union find in Python
__author__ = 'davide'
import collections
class Element:
def __init__(self, parent, rank=0, size=1):
self.parent = parent
self.rank = rank
self.size = size
@DavideCanton
DavideCanton / queens_csp.py
Last active August 29, 2015 13:56
Solutor of N-queens problem using Min-conflicts
__author__ = 'davide'
import sys
import random
import itertools as it
import operator
from functools import lru_cache
from collections import Counter
@DavideCanton
DavideCanton / Main.hs
Last active December 30, 2015 00:39
Paolify
module Main where
import Data.Char
import Control.Monad
import System.IO
type Token = (String, Bool)
mySplit :: (Char -> Bool) -> String -> [Token]
mySplit _ "" = []
@DavideCanton
DavideCanton / factor.scm
Created September 20, 2013 23:05
Integer factorization in Chez Scheme
(define factor
(lambda (n)
(let ([next (lambda (i)
(if (zero? (modulo i 2))
(1+ i)
(+ 2 i)))])
(let f ([n n] [i 2])
(let ([d (/ n i)] [s (sqrt n)])
(cond
[(>= i s) (list n)]
@DavideCanton
DavideCanton / BF_Interpreter.h
Last active December 22, 2015 19:09
Brainf*ck interpreter in C++
#ifndef BFINTEPRETER_H_
#define BFINTEPRETER_H_
#include <iostream>
#include <cstdint>
#include <vector>
using namespace std;
namespace BF
@DavideCanton
DavideCanton / bitset.h
Created September 9, 2013 10:57
bitset C++
class dyn_bitset
{
using byte_t = uint_fast8_t;
private:
int _size, _bits;
byte_t* _buf;
public:
dyn_bitset(int n)
@DavideCanton
DavideCanton / pokemon.py
Created July 16, 2013 19:26
Pokemon move effect
__author__ = 'davide'
import operator
NO_EFFECT, NOT_EFFECTIVE, NORMAL, SUPEREFFECTIVE = range(4)
TYPES = list(zip(['Normale', 'Fuoco', 'Acqua', 'Elettro', 'Erba', 'Ghiaccio',
'Lotta', 'Veleno', 'Terra', 'Volante', 'Psico', 'Coleottero',
'Roccia', 'Spettro', 'Drago', 'Buio', 'Acciaio'], range(17)))