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
''' | |
Just for fun. | |
参考文章: https://wanakiki.github.io/2020/leetcode-spider/ | |
''' | |
import requests, json | |
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36" | |
url = "https://leetcode-cn.com/graphql" | |
session = requests.Session() |
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
# 源代码来自 @Wind | |
# need py >= 3.8 | |
''' | |
已知一个黑箱里有10个红球、20个白球、30个蓝球。它们除了颜色之外,其它方面都一模一样。我们每次可以伸手进去取出一个球,当然自己看不到所取球的颜色。 | |
问:依次取球的时候,红球最先被取完的概率是多少? | |
''' | |
import random | |
noRedTime, noWhiteTime, noBlueTime = 0, 0, 0 | |
c = ["红"] * 10 + ["白"] * 20 + ["蓝"] * 30 |
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
# https://stackoverflow.com/a/45064163/13040423 | |
import time | |
import psutil | |
count = 0 | |
qry = "" | |
ul = 0.00 | |
dl = 0.00 |
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 doctest import testmod | |
from math import dist as 距离 | |
from pathlib import Path | |
from random import sample | |
from statistics import fmean | |
from typing import List, Tuple | |
Point = Tuple[float, ...] | |
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 math import dist | |
from pathlib import Path | |
from random import choice, sample | |
from typing import List, Tuple | |
Point = Tuple[float, ...] | |
def kmedoids(点集: List[Point], k: int): | |
初始点集合 = sample(点集, k) |
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 defaultdict | |
from pathlib import Path | |
from typing import Any, List, Union | |
PATH = Path(__file__).parent.absolute() | |
def 载入数据(filename: Union[Path, str]): | |
with open(PATH / filename) as f: | |
yield from (set(map(int, i.split())) for i in f) |
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
# https://scikit-learn.org/stable/modules/svm.html | |
# https://blog.csdn.net/Liii_NN/article/details/108437424 | |
from pathlib import Path as 路径 | |
from numpy import loadtxt as 载入数据 | |
from numpy import ndarray as n维数组 | |
from sklearn import svm | |
当前目录: 路径 = 路径(__file__).parent.absolute() | |
训练样本: n维数组 = 载入数据(当前目录 / "train_sample.txt") |
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 __future__ import annotations | |
from doctest import testmod | |
from operator import add, mul, sub | |
from typing import Any, Callable | |
__all__ = ["pipe"] | |
__author__ = "wuyudi" | |
__license__ = "MIT" | |
__version__ = "1.0.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
def bfs(t: int): | |
vis = set() | |
q = [1] | |
level = 0 | |
while q: | |
for _ in range(len(q)): | |
t = q.pop(0) | |
if t == 2013: | |
return level | |
for j in [t + 1, t * 2]: |
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 argparse | |
from collections import defaultdict | |
from typing import DefaultDict | |
def generateDict(): | |
def read(): | |
with open("./raw.txt") as f: | |
yield from f |
OlderNewer