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
#!python3 | |
from collections import deque | |
class TreeNode: | |
def __init__(self, val): | |
self.val = val | |
self.left = None | |
self.right = None |
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
def combinations(iterable, r, start=0): | |
''' | |
A generator that yields the combinations of the iterable object. | |
This generator has the same interface as the built-in generator | |
`itertools.combinations`. This function is faster than the official | |
demostration when the r is closed to the half of length of the input | |
iterable object. | |
''' | |
pool = tuple(iterable) |
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
import inspect | |
descriptor_records = [] | |
class Descriptor(object): | |
def __init__(self, value=None): | |
self.value = value | |
def __get__(self, instance, owner): # owner == instance.__class__ |
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
#-*- coding:utf8 -*- | |
from pprint import pprint | |
from time import time | |
def bottle_arrange(bottle_num, mouse_num): | |
mice = list(range(0, mouse_num)) | |
bottle_combination = 2**bottle_num | |
while True: | |
for i in range(mouse_num - 1, -1, -1): | |
if mice[i] < bottle_combination - mouse_num + 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
#-*- coding:utf-8 -*- | |
import math | |
from pprint import pprint | |
combinations = {} | |
def combination(m, n): | |
if n > m: return 0 | |
if n == 0 or n == m: | |
return 1 |
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 <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#define BOARD_H 4 | |
#define BOARD_W 8 | |
typedef struct chess | |
{ |
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
#-*- coding:utf-8 -*- | |
import random | |
import math | |
from functools import reduce | |
def random_point_in_sphere(r): | |
while True: | |
x = random.uniform(-r, r) | |
y = random.uniform(-r, r) | |
z = random.uniform(-r, r) |
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 <stdio.h> | |
void print_sp(int startOffset, endOffset) | |
{ | |
int i; | |
unsigned *pp = (unsigned*)&p; | |
register unsigned sp asm ("sp"); | |
pp = (unsigned*)sp; | |
for (i = startOffset; i <= endOffset; i+=4) { |
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 <stdexcept> | |
#include <string> | |
#include <cstdio> | |
std::string exec(const char *cmd) | |
{ | |
int bufferSz = 512; | |
char buffer[bufferSz]; | |
std::string result = ""; | |
FILE *pipe = popen(cmd, "r"); |
NewerOlder