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
    
  
  
    
  | #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| class SegmentTree(object): | |
| """ | |
| process sequence mutable structure, O(log(n)) query time, O(log(n)) update time. | |
| top-down-recersive-split | |
| down-top-backtrack-update | |
| - build | |
| - query | 
  
    
      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
    
  
  
    
  | ''' | |
| Question: Given n points on a x-y axis, if it exists a line that makes each point has symmetry point against this line. | |
| Algorithm: | |
| Brute Force O(n ^ 3): find n^2 lines between any two points, and test each line make all points symmetric | |
| Better algorithm O(n ^ 2): | |
| Observations: | |
| Let's name this line L, which makes all points symmetric. | |
| If we only have point A and point B, | 
  
    
      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
    
  
  
    
  | ''' | |
| Use inverted index algorithm to enable simple movie recommandation | |
| ''' | |
| import collections | |
| class User: | |
| def __init__(self, uid): | |
| self.uid = uid | |
| self.movies = [] | 
  
    
      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
    
  
  
    
  | #!/usr/bin/env python3 | |
| import random | |
| class GameBoard(object): | |
| def __init__(self, N=4): | |
| self.board = [[0 for _ in range(N)] for _ in range(N)] | |
| self.N = N | |
| self.add_chip(self.get_choices()) | 
  
    
      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
    
  
  
    
  | #!/bin/sh | |
| # Git pre-commit hook | |
| ##################### | |
| # | |
| # - check for whitespace problems (trailing spaces, ...) | |
| # - check for lines with 'FIXME' | |
| # - running tests with Python 2.7, Python 3.4 and PyPy | |
| # - running code style check (pep8) on modified files | |
| # - designed for Windows, for Linux replace `> NUL` with `> /dev/null` | 
NewerOlder