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
| """ | |
| This mimic the behavior of clojure's Thread-end ->> | |
| """ | |
| from functools import reduce, wraps | |
| from typing import Callable | |
| def double_rightarrow_decorator(f: Callable): |
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
| """ | |
| usage: python3 this_file.py expr | |
| for example: | |
| python3 this_file.py "tan(x)" | |
| python3 this_file.py "^(x,-1)" | |
| python3 this_file.py "+(x,-1)" | |
| python3 this_file.py "+(-1,x,^(x,-1))" | |
| """ | |
| import json |
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
| (* | |
| written in 2018/8/29 | |
| *) | |
| Clear["Global`*"]; | |
| (*f[x,y]=0,(x1,y1),g[x,y]=0,(x2,y2) 本代码略去了两条曲线正好相切于同一点处的切线*) | |
| f[x_, y_] = (x)^2 + x y + y^2 - 1; | |
| g[x_, y_] = (x - 4)^2 + x y + (y)^2 - 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
| from functools import wraps | |
| from typing import Callable | |
| def wrapper(f: Callable): | |
| @wraps(f) | |
| def inner(*args): | |
| if len(args) == 1 and isinstance(args[0], Callable): | |
| def curry(x): |
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
| lei[n_Integer] := | |
| Range[0, n] // | |
| 1 + 2 # & // | |
| Partition[#, 2] & // | |
| Map[1./Times @@ # &] // | |
| Total // | |
| #*8 &; | |
| lei[10000] | |
| lei2[n_Integer] := MapThread[#2 *1./#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
| from enum import Enum, auto | |
| from typing import Any, Callable | |
| class msg(Enum): | |
| FIRST = auto() | |
| SECOND = auto() | |
| def cons(x: Any, y: Any): |
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
| from typing import List | |
| import requests | |
| from lxml.etree import HTML | |
| headers = { | |
| "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0", | |
| } | |
| params = ( |
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
| #!/bin/bash | |
| for fn in "$@" | |
| do | |
| [[ -s "$fn" ]] && iconv < "$fn" -f $(uchardet "$fn") -t utf8 | less | |
| done | |
| # you can just use it like cat, alias cat=autocat.sh |
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 argparse | |
| from collections import defaultdict | |
| from typing import DefaultDict | |
| def generateDict(): | |
| def read(): | |
| with open("./raw.txt") as f: | |
| yield from f |
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 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]: |