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 maximum_path(array, n): | |
dp = [[0 for __ in xrange(n)] for _ in xrange(n)] | |
dp[0][0] = array[0][0] | |
for i in xrange(1, n): | |
for j in xrange(i + 1): | |
if j == 0: | |
dp[i][j] = array[i][j] + dp[i - 1][j] | |
elif j == i: | |
dp[i][j] = array[i][j] + dp[i - 1][j - 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
def memoize(f): | |
memo = {} | |
def inner(v): | |
if v <0: return memo | |
if not v in memo: | |
memo[v] = f(v) | |
return memo[v] | |
return inner |
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 gcd(a, b): | |
while b: | |
a, b = b, a % b | |
return a |
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 lcm(a, b): | |
return a * b // gcd (a, 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
# -*- coding: utf-8 -*- | |
uj = u'こんにちは' | |
ue = u'Hello' | |
sj = 'こんにちは' | |
se = 'Hello' | |
print ue == se # True | |
print uj == sj # False Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal | |
print sj.decode('utf-8'), type(sj.decode('utf-8')) #こんにちは |
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
class Clustering: | |
def _analyzer(self, text): | |
ret = [] | |
tagger = MeCab.Tagger("-Ochasen") | |
if type(text) == UnicodeType: | |
text = text.encode("utf-8") | |
node = tagger.parseToNode(text) | |
while node.next: | |
basic = unicode(node.feature.split(',')[-3], 'utf-8') | |
if basic != u"*": |
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 MeCab | |
import numpy as np | |
from types import * | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
from sklearn.cluster import KMeans, MiniBatchKMeans | |
from sklearn.decomposition import TruncatedSVD | |
from sklearn.preprocessing import Normalizer |
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 math | |
memo = [] | |
Ds = [] | |
Ps = [] | |
def table(r, c): | |
if r >= N or c >= N: | |
return 0 |
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 <iostream> | |
#include <map> | |
#include <string> | |
#include <vector> | |
#define FOR(i,a,b) for(int i=(a);i<(b);++i) | |
#define REP(i,n) FOR(i,0,n) | |
using namespace std; |
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 urllib2 | |
import urlparse | |
import lxml.html | |
IMAGE_FORMAT = (".jpg", ".png", ".gif") | |
class ImageExtractor: | |
def extract_main_image(self, url): |