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
| # !encoding=utf8 | |
| # primes = filterPrime [2..] | |
| # where filterPrime (p:xs) = | |
| # p : filterPrime [x | x <- xs, x `mod` p /= 0] | |
| # Infinite List | |
| from pipe import * | |
| from pipe import itertools | |
| def primes(xs): |
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
| # https://codingstyle.cn/topics/202 | |
| def f(n, p=2): | |
| if n < 2: return [] | |
| if n % p == 0: return [p] + f(n/p, p) | |
| return f(n, p+1) | |
| assert [2,2,3,3,3,5,5,19] == f(2*2*3*3*3*5*5*19) |
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
| #! /usr/local/bin/python | |
| # -*- coding: utf-8 -*- | |
| import subprocess, time | |
| # 程序执行终止时间为当前时刻延迟N秒 | |
| stoptime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()+60)) | |
| def main(command): | |
| popen = subprocess.Popen( |
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 random | |
| TIMES = 10000 | |
| def once(acc=0, days=0): | |
| return days if acc >= 20 else once(acc + random.choice(xrange(1,7)), days + 1) | |
| s1 = [once() for i in xrange(TIMES)] | |
| s1.sort() |
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 balance_recurse(chars, cnt=0): | |
| if len(chars) == 0: return cnt == 0 | |
| if chars[0] == '(': cnt += 1 | |
| if chars[0] == ')': cnt -= 1 | |
| return cnt >= 0 and balance(chars[1:], cnt) | |
| PARENS = (('(', ')'), ('[', ']'),) | |
| def balance_recurse_mul(chars, cnt=[0]*len(PARENS)): | |
| if len(chars) == 0: return all(map(lambda b: b==0, cnt)) | |
| for i, paren in enumerate(PARENS): |
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
| #!/usr/local/bin/python | |
| # -*- coding: UTF-8 -*- | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| def predict(input_vec, f): | |
| # print (input_vec, W) | |
| return f(np.dot(input_vec, W)) |
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 scrapy | |
| class BookSpider(scrapy.Spider): | |
| name = "books" | |
| start_urls = ['http://books.toscrape.com/'] | |
| def parse(self, response): | |
| for book in response.css('article.product_pod'): | |
| name = book.xpath('./h3/a/@title').extract_first() | |
| price = book.css('p.price_color::text').extract_first() |
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 scrapy | |
| class CsxCourseSpider(scrapy.Spider): | |
| name = "csx" | |
| start_urls = ['https://www.scrumalliance.org/courses-events/course.aspx?pageCount=50&country=&state=&city=&zip=&type=Csd;&trainer=&language=&startdate=5/15/2017%2012:00:00%20AM&enddate=1/1/1900%2012:00:00%20AM&discount=False&page=1&orderby=StartDate&sortdir=asc&radius=0&view=map'] | |
| # https://www.scrumalliance.org/courses-events/courses/csd/us/ohio/columbus/2017/may/201702145-csd | |
| def parse(self, response): | |
| # print '}}}}}}}}', response.url, response.xpath('*//tr') |
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 "include.hpp" | |
| #include <iostream> | |
| #include <fstream> | |
| #include <string> | |
| #include <vector> | |
| using std::cout; | |
| using std::endl; | |
| using std::string; | |
| using std::ifstream; | |
| using std::ofstream; |
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
| #!encoding=utf8 | |
| """ | |
| 建立在山峰和峡谷的城堡酒店,看具体描述:https://coding.net/u/wanghao/p/The-Castle-Company/git/blob/master/README.md | |
| 建立在山峰和峡谷的城堡酒店 | |
| 给定一组整数数组,可以把它们想象成高度,如[3,2,5,6,7,5,3]从而形成一条地形数据。 | |
| 要求:找到所有的峰值和谷值的总数,所谓峰值就是他之前的数字和之后的数字都比他小,谷值就是之前和之后的数字都比他大。 | |
| 如 [2,4,3]中 4 可以记为一个峰值, [5,3,6]中3可以记为一个谷值,这个峰/谷值可以是一个数或者一系列相同的数,如 [3,5,5,5,4] 三个 5 可以看作是一个峰值。 |