This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <vector> | |
| #include <unordered_map> | |
| #include <iostream> | |
| using namespace std; | |
| template <typename K, typename V> | |
| struct LRUNode { | |
| K key; | |
| V value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from multiprocessing import Process, Queue | |
| import random | |
| import time | |
| def f(i, q): | |
| t = random.random() * 2 | |
| time.sleep(t) | |
| print 'hello world', i | |
| q.put((i, 'hello world from %d' % i)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <memory> | |
| using namespace std; | |
| struct dummy_t { | |
| dummy_t(){} | |
| dummy_t(int v):val(v){ | |
| cout << "dummy " << val << " constructred." << endl; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vertices :: Integer -> Integer -> Integer -> [(Integer, Integer)] | |
| vertices 1 w h = [(quot (w+1) 2, h)] | |
| vertices n w h = foldl (\acc v -> acc ++ [((fst v) - dx, snd v), (fst v, (snd v) - dy), ((fst v) + dx, snd v)]) [] p | |
| where p = vertices (n-1) w h | |
| dx = quot (w+1) (2^n) | |
| dy = quot h (2^(n-1)) | |
| inrange :: Integer -> Integer -> Integer -> Bool | |
| inrange 0 x y = abs (x - 32) < y | |
| inrange n x y = inrange (n-1) x y && (foldl (\acc v -> acc && (not (abs (x-(fst v)) <= (snd v) - y && (snd v) - y < dy))) True verts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <stack> | |
| #include <stdlib.h> | |
| #include <algorithm> | |
| #include <cfloat> | |
| using namespace std; | |
| struct Point { | |
| Point():x(0), y(0){} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for /l %%x in (11, 1, 27) do ( | |
| echo 0%%x | |
| :: do something here | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <time.h> | |
| #include <vector> | |
| using namespace std; | |
| int main(int argc, char **argv) { | |
| const int MAX = 10000; | |
| vector<vector<double>> A(MAX, vector<double>(MAX)); | |
| vector<double> x(MAX), y(MAX); | |
| for(int i=0;i<MAX;++i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <algorithm> | |
| using namespace std; | |
| template <typename Container> | |
| bool nextperm(Container &s) { | |
| using T = Container; | |
| typename T::iterator first = s.begin(); | |
| typename T::iterator last = s.end() - 1; | |
| typename T::iterator i = last; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| using namespace std; | |
| const int trunk_size = 8 * 1024 * 1024; | |
| class A { | |
| public: | |
| static int counter; | |
| A() { id = counter++; cout << "alloc " << id << " @ " << this << endl; trunk.resize(trunk_size); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node(object): | |
| def __init__(self, val, leftchild=None, rightchild=None): | |
| self.val = val | |
| self.left = leftchild | |
| self.right = rightchild | |
| def bfs_iterative(tree, visitor): | |
| q = [] | |
| q.append((tree, 0)) |