Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| M[16],X=16,W,k;main(){T(system("stty cbreak") | |
| );puts(W&1?"WIN":"LOSE");}K[]={2,3,1};s(f,d,i | |
| ,j,l,P){for(i=4;i--;)for(j=k=l=0;k<4;)j<4?P=M | |
| [w(d,i,j++)],W|=P>>11,l*P&&(f?M[w(d,i,k)]=l<< | |
| (l==P):0,k++),l=l?P?l-P?P:0:l:P:(f?M[w(d,i,k) | |
| ]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d | |
| -1,j,3-i):4*i+j;}T(i){for(i=X+rand()%X;M[i%X] | |
| *i;i--);i?M[i%X]=2<<rand()%2:0;for(W=i=0;i<4; | |
| )s(0,i++);for(i=X,puts("\e[2J\e[H");i--;i%4|| | |
| puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2 |
| I like to manage dotfiles without having to mess with silly symlinks or having | |
| to install/configure specific dotfile managament tools. So here's what I did: | |
| $ cd ~ | |
| $ git init . | |
| $ echo '*' > .gitignore # ignore all files by default | |
| $ echo '!.bashrc' >> .gitignore # ...and then tell git what files not to *not* ignore | |
| $ # ...add other files you may want to track to *not* ignore | |
| $ git add .bashrc # now actually add the files to git | |
| $ git add .gitignore # add the .gitignore to git |
| package crappyBird; | |
| import java.awt.Graphics; | |
| import java.awt.Rectangle; | |
| import java.awt.event.ActionEvent; | |
| import java.awt.event.ActionListener; | |
| import java.awt.image.BufferedImage; | |
| import java.io.IOException; | |
| import java.net.URL; |
| #ifdef DEBUG | |
| # define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); | |
| #else | |
| # define DLog(...) | |
| #endif |
| def repmat(matrixA, rowFinal, colFinal): | |
| return [matrixA[i] * colFinal for i in range(len(matrixA))] * rowFinal |
| To install virtualenv via pip | |
| $ pip3 install virtualenv | |
| Note that virtualenv installs to the python3 directory. For me it's: | |
| $ /usr/local/share/python3/virtualenv | |
| Create a virtualenvs directory to store all virtual environments | |
| $ mkdir somewhere/virtualenvs | |
| Make a new virtual environment with no packages |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!