Skip to content

Instantly share code, notes, and snippets.

@cocodrips
cocodrips / n-combination.coffee
Created December 15, 2014 12:44
combination-js
n_combination: (sets, n) ->
if sets.length < n or n <= 0
return []
if sets.length == n
return [sets]
if n == 1
return (c for c in sets)
@cocodrips
cocodrips / A.py
Last active August 29, 2015 14:11
CodeThankFestivalB
n, m = map(int, raw_input().split())
print max(n, m)
@cocodrips
cocodrips / union_find.py
Last active January 25, 2018 16:50
Union Find in Python
class UnionFind:
def __init__(self, n):
self.par = range(n)
self.rank = [0 for i in xrange(n)]
def find(self, x):
if self.par[x] == x:
return x
self.par[x] = self.find(self.par[x])
return self.par[x]
@cocodrips
cocodrips / cross_point.py
Created December 6, 2014 13:27
線分交差判定 p1からp2 と p3からp4が交差しているか
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def cross(p1, p2, p3, p4):
if (((p1.x - p2.x) * (p3.y - p1.y) + (p1.y - p2.y) * (p1.x - p3.x)) *
((p1.x - p2.x) * (p4.y - p1.y) + (p1.y - p2.y) * (p1.x - p4.x)) < 0):
if (((p3.x - p4.x) * (p1.y - p3.y) + (p3.y - p4.y) * (p3.x - p1.x)) *
@cocodrips
cocodrips / cross.py
Created December 6, 2014 13:26
線分交差判定 2つの線分が交差しているか
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
class Line:
def __init__(self, start, end):
self.start = start
self.end = end
@cocodrips
cocodrips / CasperJS.md
Last active August 29, 2015 14:10
CasperJS メモ

Cookie

参考:casperjsでのクッキーの保存、読み込み
基本的にはこれで動く。casperなのに、かすかに見え隠れするphantom.js...

Save

var fs = require('fs')
var cookies = JSON.stringify(phantom.cookies)
fs.write("cookie.txt", cookies, 644)
@cocodrips
cocodrips / CODERUNNER_Cluster
Last active August 29, 2015 14:10
CodeRunner 予選Bの敵の属性をK-meansで分類したやつ
0 : ( 24 48 68 73 74 89 99 )
1 : ( 20 34 46 47 54 71 78 )
2 : ( 6 13 14 16 23 25 28 29 30 37 41 43 50 51 53 55 58 59 60 61 65 66 69 70 72 75 79 83 84 85 86 88 90 92 94 97 )
3 : ( 1 7 15 26 33 36 38 64 76 80 81 91 96 100 )
4 : ( 3 17 35 44 45 52 67 77 )
5 : ( 9 10 21 27 87 )
6 : ( 4 62 82 95 98 )
7 : ( 5 18 31 39 40 56 )
8 : ( 8 12 22 32 42 57 63 )
9 : ( 2 11 19 49 93 )
@cocodrips
cocodrips / maze.py
Created October 29, 2014 08:06
迷路の幅優先 (端が全部行き止まりの場合)
import Queue
class Axis(object):
def __init__(self, x, y):
self.x = x
self.y = y
def __eq__(self, other):
return self.x == other.x and self.y == other.y
@cocodrips
cocodrips / walk.py
Last active August 29, 2015 14:08
numpyでwalk
import numpy as np
"""
o-o-o-o-o
"""
m = np.matrix([
[1, 1, 0, 0, 0],
[1, 1, 1, 0, 0],
[0, 1, 1, 1, 0],
@cocodrips
cocodrips / kruskal.cpp
Last active August 29, 2015 14:07
最小全域木を求める(クラスカル法)
#include <algorithm>
class UnionFind{
public:
int *par;
int *rank;
UnionFind(int n) {
par = new int[n]; rank = new int[n];
for (int i = 0; i < n; ++i){ par[i] = i; rank[i] = 0;}
}