Skip to content

Instantly share code, notes, and snippets.

View jo32's full-sized avatar
🎯
Focusing

jo32

🎯
Focusing
View GitHub Profile
@jo32
jo32 / azran_legacy_puzzle_07.py
Last active August 29, 2015 14:01
Python Solution of Puzzle #7 of Professor Layton: Azran Legacy
# 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]
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
@jo32
jo32 / azran_legacy_puzzle_025.py
Created June 6, 2014 17:42
azran_legacy_puzzle_025.py
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))
@jo32
jo32 / analyse.py
Created June 23, 2014 13:25
is-baidu-world-cup-prediction-reliable
import json
f = open('all.json')
json = json.loads(f.read())
f.close()
predicts = []
results = []
for i in json:
bodys = i['data']['body']
@jo32
jo32 / stack.js
Created July 31, 2015 04:47
higher performance stack implementation
// 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);
@jo32
jo32 / webpack.config.js
Created August 24, 2015 03:22
pixi.js + webpack
// 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"
},
@jo32
jo32 / quicksort.js
Last active September 23, 2015 09:42
quicksort, quick sort
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;
}
}
@jo32
jo32 / mergesort.js
Last active September 24, 2015 03:43
mergesort, merge sort
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);
@jo32
jo32 / heapsort.js
Created September 25, 2015 09:52
heapsort, heap sort
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() {
@jo32
jo32 / plusposts.html
Created December 3, 2011 13:33
Google Plus Sidebar for Octopress
<!--
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 -->