This file contains 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
# sample input: [1, -1, 0, -1, -1] | |
# means one sailor on the first plank, the third plank | |
# is the one with nothing and the left are pirates. | |
# sample output: | |
# 00 [1, -1, 0, -1, -1] | |
# 01 [0, 1, 1, -1, -1] | |
# 02 [-1, -1, -1, 0, -1] | |
# 03 [-1, 0, 1, -1, -1] | |
# 04 [-1, -1, -1, 1, 0] |
This file contains 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 collections import deque | |
from functools import reduce | |
a = deque([9, 6, 6, 6]) | |
b = deque([7, 1, 5, 3]) | |
c = deque([4, 3, 2, 8]) | |
def is_satisfied(a, b, c): | |
avg = (sum(a) + sum(b) + sum(c)) / 4 |
This file contains 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 itertools import combinations | |
from functools import reduce | |
from operator import xor | |
a = [1, 2, 4, 7, 15, 31] | |
s = set([]) | |
for i in range(1, len(a) + 1): | |
for e in combinations(a, i): | |
s.add(sum(e)) |
This file contains 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 json | |
f = open('all.json') | |
json = json.loads(f.read()) | |
f.close() | |
predicts = [] | |
results = [] | |
for i in json: | |
bodys = i['data']['body'] |
This file contains 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
// jsperf link: http://jsperf.com/jsstacktest | |
var Stack = function(opts) { | |
opts = opts || {}; | |
var capacity = opts.capacity; | |
if (!capacity) { | |
capacity = 64; | |
} | |
this.capacity = capacity; | |
this.list = new Array(this.capacity); |
This file contains 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
// supose you have pixi.js installed using `npm install pixi.js`, you can have webpacked worked by setting the webpack.config.js like: | |
var Clean = require('clean-webpack-plugin'); | |
var path = require('path'); | |
module.exports = { | |
entry: "./src/index.js", | |
output: { | |
path: __dirname, | |
filename: "bundle.js" | |
}, |
This file contains 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
Array.prototype.quickSort = function(comp) { | |
var temp; | |
if (!comp) { | |
comp = function(a, b) { | |
a = a.toString(); | |
b = b.toString(); | |
return a <= b ? (a == b ? 0 : -1) : 1; | |
} | |
} |
This file contains 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
Array.prototype.mergeSort = function(comp) { | |
if (!comp) { | |
comp = function(a, b) { | |
a = a.toString(); | |
b = b.toString(); | |
return a <= b ? (a < b ? -1 : 0) : 1; | |
} | |
} | |
var tempArray = new Array(this.length); |
This file contains 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
Array.prototype.heapSort = function(comp) { | |
if (!comp) { | |
comp = function(a, b) { | |
a = a.toString(); | |
b = b.toString(); | |
return a <= b ? (a < b ? -1 : 0) : 1; | |
} | |
} | |
var __heapify = (function() { |
This file contains 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
<!-- | |
JSON-P Google Plus fetcher for Octopress | |
(c) Jolam Jiang // MIT License | |
You can see the tutorial of adding sidebar here: | |
http://bandj.us/jo/blog/blog/2011/12/03/adding-google-plus-sidebar-to-octopress/ | |
--> | |
{% if site.googleplus_user %} | |
<section> | |
<!-- load jquery --> |
OlderNewer